/* Non-critical global rules — nothing here is needed for first paint (page
   transitions and the nav progress bar only matter once the user navigates;
   prose-note only applies on novel/note content; offline overrides only
   matter once navigator.onLine goes false). Loaded non-blocking via
   <link media="print" onload="this.media='all'"> in index.php — see
   assets/styles/global.css for the render-blocking-on-purpose subset. */

/* Deep-linked review (#review-<id>) — flash the card on arrival */
.review-focus {
    border-color: rgba(167, 139, 250, 0.55) !important;
    animation: review-focus-pulse 2.4s ease-out 1;
}

@keyframes review-focus-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(167, 139, 250, 0.5);
    }

    70% {
        box-shadow: 0 0 0 12px rgba(167, 139, 250, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(167, 139, 250, 0);
    }
}

/* Page transition */
::view-transition-old(root) {
    animation: 120ms ease-in both _page-fade-out;
}

::view-transition-new(root) {
    animation: 200ms ease-out both _page-fade-in;
}

@keyframes _page-fade-out {
    to {
        opacity: 0;
    }
}

@keyframes _page-fade-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes _menu-punch-in {
    from {
        opacity: 0;
        transform: scale(0.85) translateY(-8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

#page-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: #a78bfa;
    z-index: 9999;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s ease, opacity 0.2s ease;
    pointer-events: none;
    opacity: 0;
}

/* Novel / note page styles */
.prose-note h1,
.prose-note h2,
.prose-note h3,
.prose-note h4,
.prose-note h5,
.prose-note h6 {
    color: rgb(var(--c-white));
    font-family: 'Bree Serif', Georgia, serif;
    font-weight: 700;
    margin: 0 0 0.6em;
    line-height: 1.3;
}

.prose-note h2 {
    font-size: 1.35rem;
}

.prose-note h6 {
    font-size: 0.8rem;
    color: rgb(var(--c-white) / calc(var(--ta-b,0) + var(--ta-m,1) * 0.45));
    font-weight: 500;
    letter-spacing: .04em;
}

.prose-note p {
    margin: 0 0 0.1em;
}

.prose-note p:has(> br:only-child),
.prose-note p:empty {
    margin: 0;
    min-height: 0.6em;
}

.prose-note a {
    color: rgb(var(--c-violet-light));
    text-decoration: underline;
    word-break: break-all;
}

.prose-note strong {
    font-weight: 700;
}

.reader-note+img {
    margin-top: 0;
}

/* Offline: search / notifications / profile links don't work, so drop
   the site nav and the mobile tab bar entirely. (index.php toggles
   html.is-offline from navigator.onLine.) */
html.is-offline #site-nav,
html.is-offline #mobile-tabbar {
    display: none !important;
}

html.is-offline {
    --mobile-tabbar-h: 0px;
}

/* No nav bar to clear — reclaim the top gap on the main offline page. */
html.is-offline #downloads-view {
    padding-top: 1.75rem;
}

/* Themed scrollbar for dark scrollable panels (edit-profile modal, its
   avatar-decoration grid, etc.) — matches the site's rgba(255,255,255,*)
   border/surface scale instead of the OS default scrollbar. */
.custom-scrollbar {
    scrollbar-width: thin;
    scrollbar-color: rgb(var(--c-white) / 0.18) transparent;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgb(var(--c-white) / 0.18);
    border-radius: 9999px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgb(var(--c-white) / 0.32);
}

/* Small styled hover tooltip — used for the verified/subscription-tier
   badges next to a display name. Wrap the badge in <span class="mk-tt"
   data-tip="...">; the label is drawn from data-tip via CSS instead of the
   native (slow, unstyled, per-browser-inconsistent) title attribute. Only
   sets position — leaves display alone so it composes with the wrapped
   element's own flex/inline-flex/inline classes instead of fighting them. */
.mk-tt {
    position: relative;
}

/* Only where nothing else already establishes a display type (the bare
   with_tooltip() wrapper around a single icon) — an explicit `flex`/
   `inline-flex` class alongside .mk-tt always wins by source order. */
span.mk-tt {
    display: inline-flex;
}

.mk-tt::after {
    --c-white: 255 255 255;
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translate(-50%, 4px);
    background: #1c1c20;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    padding: 5px 9px;
    border-radius: 7px;
    border: 1px solid rgb(var(--c-white) / 0.08);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease, visibility .12s;
    z-index: 60;
}

.mk-tt::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: calc(100% + 3px);
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1c1c20;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s ease, visibility .12s;
    z-index: 60;
}

.mk-tt:hover::after,
.mk-tt:hover::before,
.mk-tt:focus-visible::after,
.mk-tt:focus-visible::before {
    opacity: 1;
    visibility: visible;
    transform-origin: center;
}

.mk-tt:hover::after,
.mk-tt:focus-visible::after {
    transform: translate(-50%, 0);
}

/* Level pill hover card (profile header): "<xp> ... <next level xp>" over a gradient
   progress bar, then how much is left. --xp-bar is the bar gradient, set inline on
   the pill from the profile's accent. Shown on hover/focus like .mk-tt. */
.xp-pill {
    position: relative;
}

.xp-tip {
    --c-white: 255 255 255;
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translate(-50%, 4px);
    box-sizing: border-box;
    width: 240px;
    max-width: calc(100vw - 24px);
    padding: 12px 14px;
    border-radius: 12px;
    background: #1c1c20;
    border: 1px solid rgb(var(--c-white) / 0.08);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.5);
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: normal;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .12s ease, transform .12s ease, visibility .12s;
    z-index: 60;
}

.xp-tip::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 100%;
    margin-left: -6px;
    border: 6px solid transparent;
    border-top-color: #1c1c20;
}

.xp-pill:hover .xp-tip,
.xp-pill:focus .xp-tip {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.xp-tip-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.xp-tip-row b {
    color: #fff;
    font-weight: 700;
}

.xp-tip-row span {
    color: rgb(var(--c-white) / calc(var(--ta-b,0) + var(--ta-m,1) * 0.4));
}

.xp-tip-bar {
    display: block;
    height: 10px;
    margin-top: 10px;
    border-radius: 9999px;
    background: rgb(var(--c-white) / 0.08);
    overflow: hidden;
}

.xp-tip-bar i {
    display: block;
    height: 100%;
    border-radius: 9999px;
    background: var(--xp-bar, linear-gradient(90deg, #f472b6, #8b5cf6, #38bdf8));
}

.xp-tip-cap {
    display: block;
    margin-top: 9px;
    font-size: 11px;
    font-weight: 500;
    color: rgb(var(--c-white) / calc(var(--ta-b,0) + var(--ta-m,1) * 0.45));
}

/* Generic small inline loading spinner for buttons ("Claiming…" etc.) — the
   moving edge uses currentColor so it tints with whatever text color the
   button already has. */
@keyframes mk-spin {
    to {
        transform: rotate(360deg);
    }
}

.mk-spin {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 9999px;
    border: 2px solid rgb(var(--c-white) / 0.3);
    border-top-color: currentColor;
    animation: mk-spin .6s linear infinite;
    flex-shrink: 0;
}

/* Slow shimmer for CTA buttons whose two-color gradient comes from an inline
   `background:linear-gradient(...)` (Buy Chapter / Read via Subscription) —
   background-size needs !important because that inline `background` shorthand
   resets size to auto, which would otherwise leave this animation nothing to
   pan across. */
@keyframes mk-gradient-pan {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

.mk-anim-gradient {
    background-size: 220% 220% !important;
    animation: mk-gradient-pan 3s ease-in-out infinite;
}

/* Back-to-top button — created by assets/scripts/back-to-top.js. A dark circle pinned to the
   bottom-right with an up arrow inside and a ring around it that fills with scroll depth (the
   script owns .btt-bar's stroke-dasharray / stroke-dashoffset, set inline from the circle's
   circumference). Hidden below the md breakpoint (768px — the phone tab bar's cutoff): phones
   have the tab bar, and the script idles there. Only opacity/transform animate, so the entrance
   stays on the compositor; the ring is the one thing repainted while scrolling, and it is a 52px
   circle. No backdrop blur on purpose — it would re-blur whatever scrolls underneath on every
   frame. z-index 44 sits under the tab bar (45), the top bars (50) and every panel / modal. */
.back-to-top {
    --c-white: 255 255 255;
    position: fixed;
    right: calc(24px + env(safe-area-inset-right, 0px));
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    z-index: 44;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    padding: 0;
    border: 0;
    border-radius: 9999px;
    background: #18181f;
    color: #fff;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    /* Hidden = see-through, out of the tab order / a11y tree (visibility) and not clickable.
       visibility waits out the fade so the button doesn't just vanish. */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(14px) scale(0.9);
    transition: opacity .25s ease, transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
}

.back-to-top.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition: opacity .25s ease, transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s;
}

.btt-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg); /* start the ring at 12 o'clock */
}

.btt-track,
.btt-bar {
    fill: none;
    stroke-width: 2.5;
}

.btt-track {
    stroke: rgb(var(--c-white) / 0.16);
    transition: stroke .2s ease;
}

.btt-bar {
    stroke: #fff;
    stroke-linecap: round;
}

.btt-arrow {
    position: relative; /* paints above the absolutely positioned ring */
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}

.back-to-top:focus-visible {
    outline: 2px solid var(--zmio-accent-light, #c4b5fd);
    outline-offset: 3px;
}

/* Hover only where there is a real hover — on touch it would stick after a tap. */
@media (hover: hover) {
    .back-to-top.is-visible:hover {
        transform: translateY(-3px);
    }

    .back-to-top:hover .btt-track {
        stroke: rgb(var(--c-white) / 0.3);
    }

    .back-to-top:hover .btt-arrow {
        transform: translateY(-2px);
    }
}

.back-to-top.is-visible:active {
    transform: scale(0.94);
}

@media (prefers-reduced-motion: reduce) {
    .back-to-top,
    .back-to-top.is-visible,
    .btt-track,
    .btt-arrow {
        transition: none;
    }
}

@media (max-width: 767.98px), print {
    .back-to-top {
        display: none;
    }
}
