/* --- 3D Flip Calendar Styling --- */
.book-calendar-wrapper {
    position: relative;
    width: 100%;
    max-width: 1200px; /* Larger end-to-end */
    height: 500px;
    margin: 0 auto;
    perspective: 2500px; /* Critical for 3D effect */
    display: flex;
    justify-content: center;
    align-items: center;
}

.book {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

/* Base page styling */
.page {
    position: absolute;
    width: 100%; /* Full width single page */
    height: 100%;
    top: 0;
    left: 0; 
    transform-origin: top center; /* Flips from the top hinge */
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.645, 0.045, 0.355, 1), opacity 0.8s;
}

/* When a page is flipped up */
.page.flipped {
    transform: rotateX(180deg);
    opacity: 0; /* Fade out as it flips over */
    pointer-events: none;
}

/* Front face of the physical page */
.page-front {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    padding: 2.5rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: rgba(15, 15, 20, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    border-radius: 15px;
}

/* Calendar Grid Styles */
.month-header {
    text-align: center;
    font-size: 1.8rem;
    color: var(--neon-red, #d11a2a);
    font-weight: 700;
    margin-bottom: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 0 0 15px rgba(209, 26, 42, 0.4);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: auto repeat(6, 1fr);
    gap: 8px;
    flex-grow: 1;
}

.day-name {
    text-align: center;
    color: rgba(255,255,255,0.5);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.day-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    font-size: 1rem;
    cursor: default;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    padding: 2px;
}

.day-cell.empty {
    background: transparent;
    border: none;
}

.event-label {
    font-size: 0.6rem;
    text-align: center;
    line-height: 1.1;
    margin-top: 2px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 95%;
}

/* Event Types and Colors */
.day-cell.has-event {
    cursor: pointer;
    font-weight: 800;
    font-size: 1.1rem;
}

.day-cell.has-event:hover {
    transform: scale(1.15);
    z-index: 5;
}

.event-exam {
    background: rgba(155, 89, 182, 0.25);
    border-color: rgba(155, 89, 182, 0.8);
    color: #e056fd;
    box-shadow: 0 0 15px rgba(155, 89, 182, 0.4);
}

.event-class {
    background: rgba(46, 204, 113, 0.25);
    border-color: rgba(46, 204, 113, 0.8);
    color: #2ecc71;
    box-shadow: 0 0 15px rgba(46, 204, 113, 0.4);
}

.event-admin {
    background: rgba(52, 152, 219, 0.25);
    border-color: rgba(52, 152, 219, 0.8);
    color: #3498db;
    box-shadow: 0 0 15px rgba(52, 152, 219, 0.4);
}

.event-holiday {
    background: rgba(209, 26, 42, 0.25);
    border-color: rgba(209, 26, 42, 0.8);
    color: #ff4d4d;
    box-shadow: 0 0 15px rgba(209, 26, 42, 0.4);
}

/* Book Controls */
.book-controls {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
}

.book-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 55px;
    height: 55px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    outline: none;
}

.book-btn:hover {
    background: var(--neon-red, #d11a2a);
    border-color: transparent;
    box-shadow: 0 0 20px var(--neon-red);
    transform: scale(1.1);
}

/* Event Modal Popup */
.event-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(15px);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.event-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

@keyframes gradientSweep {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.event-modal-content {
    background: linear-gradient(135deg, rgba(209, 26, 42, 0.4), rgba(255, 255, 255, 0.15), rgba(209, 26, 42, 0.4));
    background-size: 200% 200%;
    animation: gradientSweep 4s ease infinite;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    padding: 3.5rem;
    max-width: 500px;
    width: 90%;
    position: relative;
    box-shadow: 0 30px 60px rgba(0,0,0,0.9), inset 0 0 40px rgba(209, 26, 42, 0.3);
    transform: perspective(1500px) rotateX(90deg) scale(0.3) translateY(-300px);
    opacity: 0;
    transition: all 0.8s cubic-bezier(0.68, -0.6, 0.32, 1.6); /* Super elastic 3D drop */
    text-align: center;
    backdrop-filter: blur(25px);
}

.event-modal-overlay.active .event-modal-content {
    transform: perspective(1500px) rotateX(0deg) scale(1) translateY(0);
    opacity: 1;
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 25px;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.4);
    font-size: 1.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.close-modal:hover {
    color: var(--neon-red, #d11a2a);
    transform: rotate(90deg);
}

.modal-date {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    background: rgba(255,255,255,0.05);
    border-radius: 30px;
    color: var(--neon-red, #d11a2a);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 2rem;
    border: 1px solid rgba(209, 26, 42, 0.3);
}

.modal-title {
    font-size: 2rem;
    color: #fff;
    margin-bottom: 1.5rem;
    line-height: 1.3;
}

.modal-desc {
    color: rgba(255,255,255,0.7);
    font-size: 1.1rem;
    line-height: 1.6;
}

/* Mobile Responsive */
@media (max-width: 900px) {
    .book-calendar-wrapper {
        height: 500px;
    }
    
    .page {
        width: 100%; 
        border-radius: 15px;
    }
    
    .page-front {
        border-radius: 15px;
        padding: 1rem 0.5rem; /* Maximize screen real estate for the grid */
    }
    
    .calendar-grid {
        gap: 3px;
    }

    .day-name {
        font-size: 0.7rem;
        padding-bottom: 5px;
    }
    
    .day-cell {
        font-size: 0.8rem;
        padding: 1px;
        border-radius: 6px;
    }
    
    .day-cell.has-event {
        font-size: 0.9rem;
    }

    .event-label {
        font-size: 0.5rem; /* Extremely small text to fit in mobile cells */
        letter-spacing: -0.5px;
        margin-top: 1px;
    }
    
    .month-header {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }

    .book-controls {
        gap: 1.5rem;
    }

    .book-btn {
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }

    /* Modal adjustments for small screens */
    .event-modal-content {
        padding: 2rem;
        width: 95%;
    }

    .modal-title {
        font-size: 1.4rem;
        margin-bottom: 1rem;
    }

    .modal-date {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
        margin-bottom: 1.5rem;
    }

    .modal-desc {
        font-size: 0.95rem;
    }

    /* Disable hover animation on grid cells */
    .day-cell.has-event:hover {
        transform: none;
        z-index: auto;
    }

    /* Disable 3D opening animation for popup modal */
    .event-modal-content {
        transform: none;
        transition: none;
    }
    
    .event-modal-overlay.active .event-modal-content {
        transform: none;
        transition: none;
    }
}
