/* --- GLOBAL & BODY STYLES --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: none;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    background: #121212;
    background-image: radial-gradient(circle at 1% 1%, hsla(211, 47%, 26%, 1) 0%, transparent 50%),
        radial-gradient(circle at 99% 99%, hsla(303, 56%, 22%, 1) 0%, transparent 50%);
    min-height: 100vh;
    padding: 30px;
    color: #e0e0e0;
    user-select: none;
    overflow-x: hidden;
}

/* --- MAIN CONTAINER & HEADER --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: rgba(35, 35, 35, 0.45);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    transition: all 0.3s ease; /* Added for smooth transition */
}

.header {
    background: rgba(30, 30, 30, 0.2);
    color: #ffffff;
    padding: 40px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.header h1 {
    font-size: 2.8em;
    margin-bottom: 10px;
    font-weight: 600;
    font-family: 'Montserrat', sans-serif;
}

.header h2 {
    font-size: 1.2em;
    color: #c0c0c0;
    font-weight: 300;
}

/* --- WEEK SELECTOR & BOUNCY TOGGLE --- */
.week-selector {
    display: flex;
    justify-content: center;
    padding: 30px;
    background: rgba(20, 20, 20, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    transition: all 0.3s ease; /* Added for smooth transition */
}

.week-selector-flex {
    display: flex;
    align-items: center;
    gap: 32px;
    width: 100%;
    justify-content: flex-start;
}

.week-slider-container {
    position: relative;
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 50px;
    padding: 6px;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.1);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
    overflow: hidden;
    width: 320px;
    margin-right: 0;
}

.week-slider-container:hover {
    transform: scale(1.05);
    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.15),
        0 0 0 2px rgba(0, 119, 255, 0.3);
}

.week-btn {
    position: relative;
    padding: 12px 24px;
    font-weight: 600;
    font-size: 14px;
    border-radius: 44px;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 2;
    color: #888;
    user-select: none;
    min-width: 140px;
    text-align: center;
    background: transparent;
    border: none;
    cursor: pointer;
    flex: 1;
    outline: none;
}

.week-btn.active {
    color: white;
    transform: scale(1.02);
}

.week-btn:hover:not(.active) {
    color: #bbb;
    transform: scale(1.05);
}

.week-slider {
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc(50% - 6px);
    height: calc(100% - 12px);
    background: linear-gradient(135deg, #0077ff, #005ce6);
    border-radius: 44px;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1;
    box-shadow:
        0 4px 12px rgba(0, 119, 255, 0.4),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.week-slider::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), transparent);
    border-radius: 44px;
    transition: all 0.3s ease;
}

.week-slider-container:hover .week-slider::before {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), transparent);
}

/* Active state for second option */
.week-slider-container.week2 .week-slider {
    left: calc(50%);
}

/* Stretch animation on click */
.week-slider-container.stretching .week-slider {
    transform: scaleX(1.1);
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Bounce back animation */
.week-slider-container.bouncing .week-slider {
    animation: bounceBack 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounceBack {
    0% {
        transform: scaleX(1.1);
    }

    30% {
        transform: scaleX(0.95);
    }

    60% {
        transform: scaleX(1.05);
    }

    100% {
        transform: scaleX(1);
    }
}

/* Ripple effect */
.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: ripple-animation 0.6s linear;
    pointer-events: none;
}

@keyframes ripple-animation {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* Glow effect on active */
.week-slider-container.week1 .week-slider,
.week-slider-container.week2 .week-slider {
    animation: glow-blue 2s ease-in-out infinite alternate;
}

@keyframes glow-blue {
    from {
        box-shadow:
            0 4px 12px rgba(0, 119, 255, 0.4),
            inset 0 1px 2px rgba(255, 255, 255, 0.3);
    }

    to {
        box-shadow:
            0 6px 20px rgba(0, 119, 255, 0.6),
            inset 0 1px 2px rgba(255, 255, 255, 0.3);
    }
}

/* --- TIMETABLE & ANIMATIONS --- */
.timetable-container {
    padding: 30px;
    position: relative;
    min-height: 500px;
    transition: all 0.3s ease; /* Added for smooth transition */
}

.week-content.fade-in-up {
    animation: fadeInUp 0.35s ease-out forwards;
}

.week-content.fade-out-down {
    animation: fadeOutDown 0.35s ease-out forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

@keyframes fadeOutDown {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(20px);
        visibility: hidden;
    }
}

.timetable {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
    border-radius: 8px;
    overflow: hidden;
    table-layout: fixed;
}

.timetable th,
.timetable td {
    padding: 14px 12px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top-width: 0;
    border-left-width: 0;
    vertical-align: top;
    transition: background-color 0.3s ease;
}

.timetable th:first-child,
.timetable td:first-child {
    border-left-width: 1px;
}

.timetable tr:first-child th {
    border-top-width: 1px;
}

.timetable th {
    background: rgba(26, 26, 26, 0.4);
    color: #ffffff;
    padding: 18px 12px;
    font-weight: 600;
    font-size: 1em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.timetable thead tr:first-child th:first-child {
    border-top-left-radius: 8px;
}

.timetable thead tr:first-child th:last-child {
    border-top-right-radius: 8px;
}

.timetable tbody tr:last-child td:first-child {
    border-bottom-left-radius: 8px;
}

.timetable tbody tr:last-child td:last-child {
    border-bottom-right-radius: 8px;
}

.timetable th.day-header {
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

.timetable th.day-header:hover {
    background: rgba(50, 50, 50, 0.6);
    transform: translateY(-2px);
}

.timetable tbody tr:hover td {
    background: rgba(255, 255, 255, 0.05);
}

.period-time {
    background: rgba(26, 26, 26, 0.4);
    color: #ffffff;
    font-weight: 600;
    font-size: 0.9em;
}

.subject {
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 5px;
}

.teacher {
    color: #b0b0b0;
    font-size: 0.85em;
    font-weight: 300;
}

.room {
    color: #79c0ff;
    font-size: 0.8em;
    font-weight: 500;
}

.break,
.registration {
    background: rgba(60, 60, 60, 0.3);
    color: #ffffff;
    font-weight: 600;
}

.empty {
    background: rgba(34, 34, 34, 0.15);
    color: #666666;
    font-style: italic;
}

/* --- HIGHLIGHTING STYLES --- */
.highlight-current {
    outline: 2px solid #1fdd12;
    outline-offset: -2px;
    box-shadow: 0 0 12px rgba(31, 221, 18, 0.4);
}

.highlight-next {
    outline: 2px solid #006ddb;
    outline-offset: -2px;
    box-shadow: 0 0 12px rgba(0, 109, 219, 0.4);
}

/* --- MODAL (POPUP) STYLES --- */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ================== CSS MODIFICATION START ================== */
.modal-content {
    position: fixed;
    top: calc(50vh - 250px);
    left: calc(50vw - 250px);
    opacity: 0;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease-out;
    background-color: rgba(50, 50, 50, 0.155);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(25px);
    padding: 35px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    height: 500px; /* Fixed height is necessary for scrolling to work */
    width: 500px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.37);
    color: #e0e0e0;
    overflow-y: auto; /* THIS IS THE KEY PROPERTY FOR SCROLLING */
    scrollbar-width: none;
}
/* ================== CSS MODIFICATION END ================== */

.modal.show .modal-content {
    opacity: 1;
    transform: scale(1);
}

.modal-content h3 {
    text-align: center;
    margin-bottom: 25px;
    font-size: 1.8em;
    color: #ffffff;
    font-weight: 600;
}

.modal-content ul {
    list-style-type: none;
    padding: 0;
    margin-bottom: 20px;
}

/* This is the original simple style for each book item */
.modal-content ul li {
    background: rgba(30, 30, 30, 0.4);
    margin-bottom: 10px;
    padding: 15px;
    border-radius: 6px;
    font-size: 1.1em;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 25px;
    font-size: 35px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s, transform 0.3s;
}

.close-button:hover,
.close-button:focus {
    color: #fff;
    transform: rotate(90deg);
}

#noBooksMessage {
    text-align: center;
    font-style: italic;
    color: #b0b0b0;
    margin-top: 15px;
}

/* --- RESPONSIVE DESIGN --- */
@media (max-width: 768px) {
    body {
        padding: 15px;
    }

    .timetable {
        font-size: 0.8em;
    }

    .timetable th,
    .timetable td {
        padding: 10px 6px;
    }

    .header h1 {
        font-size: 2em;
    }

    .modal-content {
        width: 95%;
        padding: 25px;
        left: 2.5%;
        top: 10%;
        height: 80vh;
    }

    .modal-content h3 {
        font-size: 1.5em;
    }
}

.lesson-info-boxes {
    display: flex;
    gap: 12px;
    align-items: center;
}

.lesson-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
    padding: 6px 10px;
    border-radius: 15px;
    border: 2px solid #3ad;
    background: #1c1c1c;
    font-size: 0.85em;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 48px;
}

.lesson-box.next-lesson {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 50px;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.3),
    inset 0 2px 4px rgba(255, 255, 255, 0.1);
  border: none;
  min-width: 120px;
  padding: 6px 10px;
  height: 48px;
  color: #fff;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  font-size: 0.85em;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.next-lesson {
    border-color: #3498db;
}

.lesson-label {
    display: none;
}

.lesson-name {
    font-size: 0.95em;
    font-weight: 500;
    margin-bottom: 2px;
    text-align: center;
    max-width: 80px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lesson-countdown {
    font-size: 0.8em;
    color: #888;
    text-align: center;
}

.compact-toggle {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 50px;
    box-shadow:
        0 10px 30px rgba(0, 0, 0, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    font-size: 1.3em;
    line-height: 1;
    padding: 6px 10px;
    height: 48px;
    width: 48px;
    margin-left: 16px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.compact-toggle:hover {
    transform: scale(1.05);
    box-shadow:
        0 15px 40px rgba(0, 0, 0, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.15),
        0 0 0 2px rgba(0, 119, 255, 0.3);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- COMPACT MODE STYLES (REVISED) --- */

/* 1. Main layout adjustments */
body.compact-mode {
    padding: 0;
    overflow: hidden; /* Prevent body scroll */
}
body.compact-mode .container {
    display: flex;
    flex-direction: row;
    height: 100vh;
    max-width: 100%;
    border-radius: 0;
    padding: 0;
    margin: 0;
    border: none;
    box-shadow: none;
    background: transparent;
}
body.compact-mode .header {
    display: none !important;
}

/* 2. Repurpose .week-selector as a sidebar */
body.compact-mode .week-selector {
    display: flex !important; /* Override original 'display: none' */
    flex-direction: column;
    flex: 0 0 90px; /* Sidebar width */
    height: 100vh;
    padding: 20px 10px;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(25, 25, 25, 0.5);
    justify-content: flex-start;
    align-items: center;
    border-bottom: none;
}
body.compact-mode .week-selector-flex {
    flex-direction: column;
    align-items: center;
    gap: 25px;
    width: 100%;
}

/* 3. Re-enable and style controls inside the sidebar */
body.compact-mode .lesson-info-boxes,
body.compact-mode .lesson-box {
    display: flex !important; /* Override original 'display: none' */
}
body.compact-mode .lesson-info-boxes {
    flex-direction: column;
    align-items: center;
    gap: 25px;
}
body.compact-mode .compact-toggle {
    margin-left: 0; /* Remove horizontal margin */
    order: 2; /* Put compact toggle button at the bottom */
}
body.compact-mode .next-lesson {
    order: 1; /* Keep next lesson at top */
    min-width: 100px;
}
body.compact-mode .lesson-name {
    font-size: 0.85em;
}

/* 4. Adjust the week slider for vertical layout */
body.compact-mode .week-slider-container {
    flex-direction: column;
    width: 60px;
    height: 120px;
    padding: 6px;
}
body.compact-mode .week-btn {
    min-width: auto;
    width: 100%;
    padding: 10px 0;
    font-size: 1.2em;
    font-weight: 700;
}
body.compact-mode .week-slider {
    width: calc(100% - 12px);
    height: calc(50% - 6px);
    left: 6px;
    top: 6px;
}
body.compact-mode .week-slider-container.week2 .week-slider {
    left: 6px; /* Keep on left */
    top: 50%; /* Move down for week 2 */
}
body.compact-mode .week-slider-container.stretching .week-slider {
    transform: scaleY(1.1); /* Stretch vertically */
}
@keyframes bounceBackVertical {
    0% { transform: scaleY(1.1); }
    30% { transform: scaleY(0.95); }
    60% { transform: scaleY(1.05); }
    100% { transform: scaleY(1); }
}
body.compact-mode .week-slider-container.bouncing .week-slider {
    animation: bounceBackVertical 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 5. Make timetable container scrollable */
body.compact-mode .timetable-container {
    flex: 1; /* Take remaining space */
    overflow-y: auto; /* Allow scrolling ONLY for the table */
    height: 100vh;
    padding: 20px;
    min-height: auto;
}

/* 6. Hide teacher/room info as requested originally */
body.compact-mode .room,
body.compact-mode .teacher {
    display: none !important;
}