/* Notification bell (js/bell.js): navbar pages and the home page */

/* =========================================================
   NOTIFICATION BELL (js/bell.js)
   Sits right after the account entry; on phones it comes before the
   small account icon. The panel drops under it (desktop) or spans the
   screen width (phones).
   ========================================================= */

.top-bell {
    position: relative;
    flex: none;
    margin-left: -20px; /* 12px from the nav links, like the butterfly */
    animation: topBellIn var(--dur-m, 260ms) var(--ease-out, ease) backwards;
}

.top-bell.no-enter {
    animation: none;
}

.top-bell.is-leaving {
    pointer-events: none;
    animation: topBellOut var(--dur-s, 180ms) var(--ease-in, ease) both;
}

@keyframes topBellIn {
    from { opacity: 0; transform: translateY(-4px) scale(.88); }
    to   { opacity: 1; transform: none; }
}

@keyframes topBellOut {
    from { opacity: 1; transform: none; }
    to   { opacity: 0; transform: scale(.88); }
}

.top-bell-btn {
    position: relative;
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    padding: 0;
    border: 1px solid rgba(143, 151, 191, .13);
    border-radius: 13px;
    background: linear-gradient(180deg, rgba(16, 23, 42, .66), rgba(8, 14, 29, .72));
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    transition:
        transform var(--dur-s, 180ms) var(--ease-out, ease),
        border-color var(--dur-s, 180ms) var(--ease-out, ease),
        background var(--dur-s, 180ms) var(--ease-out, ease),
        box-shadow var(--dur-s, 180ms) var(--ease-out, ease);
}

.top-bell-btn .icon {
    width: 1em;
    height: 1em;
    transform-origin: 50% 8%;
    transition: transform var(--dur-s, 180ms) var(--ease-out, ease);
}

@media (hover: hover) {
    .top-bell-btn:hover {
        transform: translateY(-1px);
        border-color: rgba(175, 116, 255, .4);
        background: linear-gradient(180deg, rgba(34, 31, 68, .82), rgba(16, 20, 43, .82));
    }

    .top-bell-btn:hover .icon {
        transform: rotate(-8deg);
    }
}

.top-bell-btn:active {
    transform: scale(.94);
}

.top-bell-btn:focus-visible,
.top-bell-retry:focus-visible,
.top-bell-foot:focus-visible,
.top-bell-item:focus-visible {
    outline: 2px solid var(--focus-ring, #d8b4ff);
    outline-offset: 2px;
}

.top-bell.is-open .top-bell-btn {
    border-color: rgba(216, 180, 255, .55);
    color: var(--nav-purple-soft, #d5afff);
    box-shadow: 0 0 16px rgba(185, 132, 255, .3);
}

.top-bell-btn.is-wiggle .icon {
    animation: topBellWiggle 900ms var(--ease-out, ease) .35s 1 both;
}

@keyframes topBellWiggle {
    0%   { transform: rotate(0); }
    15%  { transform: rotate(16deg); }
    30%  { transform: rotate(-14deg); }
    45%  { transform: rotate(10deg); }
    60%  { transform: rotate(-7deg); }
    80%  { transform: rotate(3deg); }
    100% { transform: rotate(0); }
}

/* unread count */
.top-bell-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border: 2px solid #0a0614;
    border-radius: 999px;
    background: #ef4458;
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
    box-sizing: border-box;
    box-shadow: 0 2px 8px rgba(239, 68, 88, .45);
    opacity: 0;
    transform: scale(.3);
    pointer-events: none;
    transition:
        opacity var(--dur-s, 180ms) var(--ease-out, ease),
        transform var(--dur-m, 260ms) cubic-bezier(.34, 1.56, .64, 1);
}

.top-bell-badge.is-on {
    opacity: 1;
    transform: none;
}

/* panel */
.top-bell-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 1100;
    width: 348px;
    max-height: min(70vh, 520px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(216, 180, 255, .25);
    border-radius: 16px;
    background: rgba(16, 9, 28, .97);
    box-shadow: 0 18px 40px rgba(0, 0, 0, .5);
    color: #f3eaff;
    transform-origin: top right;
    transform: translateY(-6px) scale(.94);
    opacity: 0;
    visibility: hidden;
    transition:
        transform var(--dur-m, 260ms) var(--ease-out, ease),
        opacity var(--dur-s, 180ms) var(--ease-out, ease),
        visibility 0s linear var(--dur-m, 260ms);
}

.top-bell.is-open .top-bell-panel {
    transform: none;
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
}

.top-bell-panel:focus {
    outline: none;
}

.top-bell-head {
    flex: none;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(216, 180, 255, .12);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .12em;
}

.top-bell-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    scrollbar-width: thin;
    scrollbar-color: rgba(185, 132, 255, .4) transparent;
}

.top-bell-item {
    position: relative;
    display: flex;
    gap: 11px;
    padding: 10px;
    border-radius: 12px;
    color: inherit;
    text-decoration: none;
    transition:
        background-color var(--dur-s, 180ms) var(--ease-out, ease),
        transform var(--dur-s, 180ms) var(--ease-out, ease);
}

.top-bell.is-open .top-bell-item {
    animation: top-rise-in var(--dur-m, 260ms) var(--ease-out, ease) backwards;
    animation-delay: calc(40ms + var(--i, 0) * 35ms);
}

@media (hover: hover) {
    .top-bell-item:hover {
        background: rgba(185, 132, 255, .12);
    }
}

.top-bell-item:active {
    transform: scale(.985);
}

.top-bell-item.is-unread {
    background: rgba(185, 132, 255, .1);
}

.top-bell-item.is-unread::after {
    content: "";
    position: absolute;
    top: 14px;
    right: 10px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b778ff;
    box-shadow: 0 0 8px rgba(183, 120, 255, .8);
}

.top-bell-item-icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(185, 132, 255, .16);
    color: #d5afff;
    font-size: 16px;
}

.top-bell-item.is-ok .top-bell-item-icon {
    background: rgba(125, 211, 168, .14);
    color: #8be0b4;
}

.top-bell-item.is-no .top-bell-item-icon {
    background: rgba(239, 68, 88, .14);
    color: #ff8a98;
}

.top-bell-item-icon .icon {
    width: 1em;
    height: 1em;
}

.top-bell-item-body {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 12px;
}

.top-bell-item-head {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.top-bell-item-quote {
    padding-left: 9px;
    border-left: 2px solid rgba(216, 180, 255, .3);
    color: rgba(234, 220, 255, .68);
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.top-bell-item-time {
    color: rgba(210, 195, 238, .45);
    font-size: 11px;
}

/* loading / empty / error */
.top-bell-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 34px 16px;
    color: rgba(234, 220, 255, .6);
    font-size: 13px;
    animation: top-fade-in var(--dur-m, 260ms) var(--ease-out, ease) both;
}

.top-bell-state p {
    margin: 0;
    text-align: center;
}

.top-bell-state-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(185, 132, 255, .12);
    color: #d5afff;
    font-size: 22px;
}

.top-bell-state-icon .icon {
    width: 1em;
    height: 1em;
}

.top-bell-spin {
    width: 22px;
    height: 22px;
    border: 2px solid rgba(216, 180, 255, .25);
    border-top-color: #d5afff;
    border-radius: 50%;
    animation: topBellSpin .8s linear infinite;
}

@keyframes topBellSpin {
    to { transform: rotate(360deg); }
}

.top-bell-retry {
    padding: 7px 18px;
    border: 1px solid rgba(216, 180, 255, .4);
    border-radius: 999px;
    background: rgba(185, 132, 255, .14);
    color: #f3eaff;
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
    transition:
        transform var(--dur-s, 180ms) var(--ease-out, ease),
        background-color var(--dur-s, 180ms) var(--ease-out, ease);
}

@media (hover: hover) {
    .top-bell-retry:hover {
        background: rgba(185, 132, 255, .28);
    }
}

.top-bell-retry:active {
    transform: scale(.94);
}

.top-bell-foot {
    flex: none;
    padding: 12px 16px;
    border-top: 1px solid rgba(216, 180, 255, .12);
    color: #d5afff;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: background-color var(--dur-s, 180ms) var(--ease-out, ease), color var(--dur-s, 180ms) var(--ease-out, ease);
}

@media (hover: hover) {
    .top-bell-foot:hover {
        background: rgba(185, 132, 255, .12);
        color: #fff;
    }
}

.top-bell-foot:active {
    background: rgba(185, 132, 255, .2);
}

/* phones and tablets: the nav folds into the menu */
@media (max-width: 1050px) {
    .top-bell {
        position: static; /* the panel is placed against the bar */
        margin-left: -22px; /* 10px from the TOP logo */
        margin-right: -22px; /* 10px to the next button */
    }

    .top-navbar:not(.has-bgm) .top-bell {
        margin-left: auto;
    }

    .top-bell ~ .top-account-mini {
        margin-left: 0;
    }

    .top-bell-btn {
        width: 44px;
        height: 44px;
        border-radius: 14px;
        border-color: rgba(171, 131, 235, .22);
        background: rgba(20, 10, 34, .72);
        -webkit-backdrop-filter: blur(10px);
        backdrop-filter: blur(10px);
        color: rgba(234, 220, 255, .86);
        font-size: 19px;
    }

    .top-bell-panel {
        top: calc(100% + 6px);
        left: 12px;
        right: 12px;
        width: auto;
        max-height: calc(100vh - 76px - 24px);
        max-height: calc(100dvh - 76px - 24px);
        transform-origin: top center;
    }
}

/* narrow phones: with the bell there are four buttons next to the logo, so
   they shrink to 40px with 6px gaps (fits 360px) */
@media (max-width: 420px) {
    .top-navbar .top-bell {
        margin-left: -26px;
        margin-right: -26px;
    }

    .top-navbar .top-bell ~ .top-account-mini {
        margin-right: -26px;
    }

    .top-navbar.has-bgm > .top-bgm {
        margin-right: -26px;
    }

    .top-navbar .top-bell-btn,
    .top-navbar .top-bell ~ .top-account-mini,
    .top-navbar .top-bell ~ .menu-toggle,
    .top-navbar.has-bgm .top-bell ~ .top-bgm .top-bgm-btn {
        width: 40px;
        height: 40px;
    }

    .top-navbar .top-bell ~ .top-bgm {
        flex: none;
    }
}

/* =========================================================
   HOME PAGE (no navbar): the bell floats beside #roomAccount, same round
   44px style and position logic as .room-account-mini in css/home.css
   (butterfly 24px, account +54px, bell +108px; phones 16 / +52 / +104)
   ========================================================= */
.top-bell.is-home {
    position: fixed;
    top: calc(24px + env(safe-area-inset-top, 0px));
    right: calc(24px + 44px + 10px + 44px + 10px + env(safe-area-inset-right, 0px));
    z-index: 60;
    margin: 0;
}

.top-bell.is-home .top-bell-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border-color: rgba(171, 131, 235, .22);
    background: rgba(20, 10, 34, .72);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    color: rgba(234, 220, 255, .86);
    font-size: 19px;
}

.top-bell.is-home .top-bell-panel {
    top: calc(100% + 10px);
    left: auto;
    right: 0;
    width: 348px;
    max-height: min(70vh, 520px);
    transform-origin: top right;
}

@media (max-width: 760px) {
    .top-bell.is-home {
        top: calc(18px + env(safe-area-inset-top, 0px));
        right: calc(16px + 44px + 8px + 44px + 8px + env(safe-area-inset-right, 0px));
    }

    .top-bell.is-home .top-bell-panel {
        position: fixed;
        top: calc(18px + 44px + 8px + env(safe-area-inset-top, 0px));
        left: 12px;
        right: 12px;
        width: auto;
        max-height: calc(100vh - 80px - env(safe-area-inset-top, 0px));
        max-height: calc(100dvh - 80px - env(safe-area-inset-top, 0px));
        transform-origin: top center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .top-bell,
    .top-bell.is-leaving,
    .top-bell.is-open .top-bell-item,
    .top-bell-state,
    .top-bell-btn.is-wiggle .icon {
        animation: none;
    }

    .top-bell-panel,
    .top-bell-badge,
    .top-bell-btn,
    .top-bell-btn .icon {
        transition-duration: 0s;
    }

    .top-bell-spin {
        animation-duration: 2.4s;
    }
}

@media print {
    .top-bell {
        display: none;
    }
}
