/* ==========================================================================
   1. FONTS & VARIABLES
   ========================================================================== */

@font-face {
    font-family: 'Inter';
    src: url('../fonts/Inter-VariableFont_wght.ttf') format('truetype-variations'),
         url('../fonts/Inter-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url('../fonts/Montserrat-VariableFont_wght.ttf') format('truetype-variations'),
         url('../fonts/Montserrat-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url('../fonts/Montserrat-Italic-VariableFont_wght.ttf') format('truetype-variations'),
         url('../fonts/Montserrat-Italic-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
}

:root {
    --font-primary: 'Inter', sans-serif;
    --font-secondary: 'Montserrat', sans-serif;

    --bg-color: #252422;
    --element-color: #403d39;
    --text-muted: #ccc5b9;
    --text: #fffcf2;
    --accent-color: #eb5e28;
    --glass-outline: color-mix(in srgb, var(--text) 10%, transparent);
    --glass-color: color-mix(in srgb, var(--element-color) 50%, transparent);
    --glass-blur: 10px;
    
    /* General UI & Interaction Variables */
    --transition-speed: 0.4s;
    --transition-curve: cubic-bezier(0.2, 0, 0, 1);

    /* Seamless Top-to-Bottom Wipe Curves (Continuous Momentum) */
    --ease-exit: cubic-bezier(0.4, 0, 1, 1);   /* Accelerates out into exit */
    --ease-entry: cubic-bezier(0, 0, 0.2, 1);  /* Starts immediately at full entry speed */

    --transition-height: 50dvh;
}

/* ==========================================================================
   2. GLOBAL RESET & ROUTER CONTAINER
   ========================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-primary);
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    height: 100vh;
    overflow: hidden;
}

body.modal-open {
    overflow: hidden;
}

/* App Viewport Container (Fixed to Visible Screen Display) */
#app-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0 1rem 140px 1rem;

    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;

    /* Base Mask: Bottom navbar blur cutout */
    -webkit-mask-image: linear-gradient(
        to bottom, 
        rgba(0, 0, 0, 1) calc(100% - 140px),
        rgba(0, 0, 0, 0.6) 100%
    );
    mask-image: linear-gradient(
        to bottom, 
        rgba(0, 0, 0, 1) calc(100% - 140px),
        rgba(0, 0, 0, 0.6) 100%
    );
}

#app-content::-webkit-scrollbar {
    display: none;
}

/* Viewport-Bound Mask Wipe Animations */
#app-content.visible {
    -webkit-animation: slideDownIn var(--transition-speed) var(--ease-entry) forwards;
    animation: slideDownIn var(--transition-speed) var(--ease-entry) forwards;
}

#app-content.exiting {
    -webkit-animation: slideDownOut var(--transition-speed) var(--ease-exit) forwards;
    animation: slideDownOut var(--transition-speed) var(--ease-exit) forwards;
}

#page-container {
    position: relative;
    width: 100%;
    max-width: 1500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: var(--transition-height);
}

/* Top-to-Bottom Mask Fade In (Entry - Viewport Display Bound) */
@keyframes slideDownIn {
    0% {
        opacity: 0;
        -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,0) calc(50% + (var(--transition-height) / 2)));
        mask-image: linear-gradient(to bottom, rgba(0,0,0,1) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,0) calc(50% + (var(--transition-height) / 2)));
        -webkit-mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        -webkit-mask-position: 0 100%;
        mask-position: 0 100%;
    }
    100% {
        opacity: 1;
        -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,0) calc(50% + (var(--transition-height) / 2)));
        mask-image: linear-gradient(to bottom, rgba(0,0,0,1) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,0) calc(50% + (var(--transition-height) / 2)));
        -webkit-mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        -webkit-mask-position: 0 0%;
        mask-position: 0 0%;
    }
}

/* Top-to-Bottom Mask Fade Out (Exit - Viewport Display Bound) */
@keyframes slideDownOut {
    0% {
        opacity: 1;
        -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,1) calc(50% + (var(--transition-height) / 2)));
        mask-image: linear-gradient(to bottom, rgba(0,0,0,0) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,1) calc(50% + (var(--transition-height) / 2)));
        -webkit-mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        -webkit-mask-position: 0 100%;
        mask-position: 0 100%;
    }
    100% {
        opacity: 0;
        -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,1) calc(50% + (var(--transition-height) / 2)));
        mask-image: linear-gradient(to bottom, rgba(0,0,0,0) calc(50% - (var(--transition-height) / 2)), rgba(0,0,0,1) calc(50% + (var(--transition-height) / 2)));
        -webkit-mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        mask-size: 100% max(calc(200dvh + var(--transition-height)), calc(200% + var(--transition-height)));
        -webkit-mask-position: 0 0%;
        mask-position: 0 0%;
    }
}

/* Media Card Touch & Gestures */
a[data-media-id] {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.anime-card {
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.anime-card.long-press-holding {
    transform: scale(0.95);
    box-shadow: 0 0 20px color-mix(in srgb, var(--accent-color) 60%, transparent);
}

/* ==========================================================================
   3. PERSISTENT APP SHELL UI
   ========================================================================== */

.profile-btn {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--glass-outline);
    background-color: var(--element-color);
    padding: 0;
    cursor: pointer;
    overflow: hidden;
    z-index: 200;
    transition: transform var(--transition-speed) var(--transition-curve),
                border-color var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-btn:hover {
    transform: scale(1.08);
    border-color: var(--accent-color);
}

.profile-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.navbar-container {
    position: fixed;
    bottom: 8px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0;
    z-index: 100;
    pointer-events: none;
}

.navbar {
    background-color: transparent;
    display: flex;
    position: relative;
    width: 90%;
    max-width: 450px;
    pointer-events: auto;
    justify-content: center;
    
    --mask-width: 140px;
    --mask-height: 140px;
}

.navbar::before {
    display: none;
    z-index: 1;
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0px;
    background-color: var(--glass-color);
    border-radius: 15px;
    border: 1px solid var(--glass-outline);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));

    transition: mask-position var(--transition-speed) var(--transition-curve),
                mask-size var(--transition-speed) var(--transition-curve),
                -webkit-mask-position var(--transition-speed) var(--transition-curve),
                -webkit-mask-size var(--transition-speed) var(--transition-curve);

    mask-image: url(navbar-cutout.svg), linear-gradient(#000, #000);
    -webkit-mask-image: url(navbar-cutout.svg), linear-gradient(#000, #000);

    mask-size: var(--mask-width) var(--mask-height), 100% 100%;
    -webkit-mask-size: var(--mask-width) var(--mask-height), 100% 100%;

    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;

    mask-position: calc(var(--x-pos) - (var(--mask-width) / 2)) calc(100% - (140px - var(--mask-height)) / 2), 0 0;
    -webkit-mask-position: calc(var(--x-pos) - (var(--mask-width) / 2)) calc(100% - (140px - var(--mask-height)) / 2), 0 0;

    mask-composite: exclude;
    -webkit-mask-composite: destination-out;
}

.navbar::after {
    display: none; 
    z-index: 2; 
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none; 
    border-radius: 15px;

    transition: mask-position var(--transition-speed) var(--transition-curve),
                mask-size var(--transition-speed) var(--transition-curve),
                -webkit-mask-position var(--transition-speed) var(--transition-curve),
                -webkit-mask-size var(--transition-speed) var(--transition-curve);

    -webkit-mask-image: url('navbar-cutout-outline.svg');
    mask-image: url('navbar-cutout-outline.svg');
    
    -webkit-mask-size: var(--mask-width) var(--mask-height);
    mask-size: var(--mask-width) var(--mask-height);
    
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;

    -webkit-mask-position: calc(var(--x-pos) - (var(--mask-width) / 2)) calc(100% - (140px - var(--mask-height)) / 2);
    mask-position: calc(var(--x-pos) - (var(--mask-width) / 2)) calc(100% - (140px - var(--mask-height)) / 2);

    background-color: var(--glass-outline);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

.nav-list {
    display: flex;
    width: 100%;
    max-width: 600px;
    list-style: none;
    position: relative;
    justify-content: space-evenly; 
}

@media (max-width: 450px) {
    .nav-list {
        justify-content: space-between;
        padding: 0 50px;
    }
}

@media (max-width: 350px) {
    .navbar-container {
        bottom: 0 !important;
    }
    .navbar {
        width: 100% !important;
        max-width: 100% !important;
    }
    .navbar::before,
    .navbar::after {
        border-radius: 0px !important;
        border-left: none !important;
        border-right: none !important;
        border-bottom: none !important;
    }
    .nav-list {
        justify-content: space-evenly !important;
        padding: 0;
    }
}

.nav-item {
    z-index: 4;
    height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    position: relative;
    transition: var(--transition-speed) var(--transition-curve);
}

.icon {
    display: none;
    font-size: 1.5rem;
    transition: transform var(--transition-speed) var(--transition-curve);
}

.text {
    display: none;
    position: absolute;
    font-family: var(--font-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    bottom: 12px;
    opacity: 0;
    transform: translateY(15px);
    transition: var(--transition-speed) var(--transition-curve);
    color: var(--text);
    pointer-events: none;
}

.nav-item.active .icon {
    transform: translateY(-33px);
}

.nav-item.active .text {
    opacity: 1;
    transform: translateY(0);
}

.indicator {
    display: none;
    background-color: var(--glass-color);
    border: 1px solid var(--glass-outline);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-radius: 50%;
    
    position: absolute;
    left: 0; 
    top: -29px;
    
    width: 58px;
    height: 58px;
    z-index: 3;
    box-sizing: border-box;

    transform-origin: center center;
    transform: translateX(var(--indicator-x, 0px)) scale(1);
    transition: transform var(--transition-speed) var(--transition-curve);
}

.no-transition::before,
.no-transition::after,
.no-transition .indicator {
    transition: none !important;
    -webkit-transition: none !important;
}

body.loaded .indicator,
body.loaded .navbar::before,
body.loaded .navbar::after,
body.loaded .icon,
body.loaded .text {
    display: block;
}

.navbar.hide-nav-effects {
    --mask-width: 0px !important;
    --mask-height: 0px !important;
}

.navbar.hide-nav-effects .indicator {
    transform-origin: center center;
    transform: translateX(var(--indicator-x, 0px)) scale(0) !important;
}

/* ==========================================================================
   4. OVERLAY SHEET & DRAGGABLE HANDLE WITH CONTINUOUS RADIUS TRANSITION
   ========================================================================== */

.overlay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 900;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) var(--transition-curve);
}

.overlay-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.overlay-sheet-viewport {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    z-index: 950;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-snap-type: y mandatory;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    pointer-events: none;
    
    scroll-timeline: --overlay-sheet-scroll y;
    
    transform: translateY(100dvh);
    transition: transform var(--transition-speed) var(--transition-curve);
    will-change: transform;
}

.overlay-sheet-viewport::-webkit-scrollbar {
    display: none;
}

.overlay-sheet-viewport.visible {
    transform: translateY(0);
    pointer-events: auto;
}

.overlay-sheet-viewport.dragging {
    transition: none !important;
}

.sheet-snap-spacer {
    height: 12dvh;
    width: 100%;
    flex-shrink: 0;
    scroll-snap-align: start;
    pointer-events: none;
}

@keyframes flattenSheetCorners {
    from {
        border-radius: 24px 24px 0 0;
    }
    to {
        border-radius: 0 0 0 0;
    }
}

.overlay-page-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    min-height: 100dvh;
    background-color: var(--bg-color);
    border-radius: 24px 24px 0 0;
    border: 1px solid var(--glass-outline);
    border-bottom: none;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.85);
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;

    animation: flattenSheetCorners linear both;
    animation-timeline: --overlay-sheet-scroll;
    animation-range: 0px 12dvh;
}

.overlay-handle-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    width: 100%;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--element-color);
    border-bottom: 1px solid var(--glass-outline);
    flex-shrink: 0;
    user-select: none;
    border-radius: inherit;
    cursor: grab;
    touch-action: none;
}

.overlay-handle-bar:active {
    cursor: grabbing;
}

.overlay-handle {
    width: 48px;
    height: 5px;
    background-color: var(--text-muted);
    border-radius: 3px;
    opacity: 0.6;
}

.overlay-close-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 10px;
    border-radius: 50%;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.overlay-close-btn:hover {
    background-color: var(--glass-outline);
    transform: translateY(-50%) scale(1.1);
}

.overlay-content {
    flex: 1;
    padding: 1.5rem;
}