html {
    height: 100vh;
}

body {
    font-family: 'Manrope', 'Noto Sans Thai', 'JetBrains Mono', monospace, sans-serif;
    height: 100vh;
    margin-bottom: 30px;
    line-height: normal;
    scroll-behavior: smooth;
}

/* Vertical centering for specific pages only */
body.center-layout {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

body.center-layout #main {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 120px); /* Viewport height minus header and footer space */
    padding-top: 60px; /* Account for fixed header */
    padding-bottom: 80px; /* Extra space for fixed footer + safe area */
    box-sizing: border-box;
    overflow-y: auto; /* Allow scrolling when content overflows */
}

/* Better overflow handling for content that's too tall */
body.center-layout #main > * {
    max-width: 100%;
    width: 100%;
}

/* Ensure scrollable content in center layout */
body.center-layout #main #intro,
body.center-layout #main .content-section {
    width: 100%;
    max-width: 100%;
    margin-bottom: 20px; /* Extra space before footer area */
}

/* Responsive adjustments for smaller screens on centered pages */
@media (max-height: 600px) {
    body.center-layout #main {
        padding-top: 50px;
        padding-bottom: 70px;
        justify-content: flex-start;
        min-height: calc(100vh - 100px);
    }
}

@media (max-height: 400px) {
    body.center-layout #main {
        padding-top: 40px;
        padding-bottom: 60px;
        justify-content: flex-start;
        min-height: calc(100vh - 80px);
    }
}

/* Ensure content doesn't get stuck behind footer on very small screens */
@media (max-height: 300px) {
    body.center-layout #main {
        padding-top: 30px;
        padding-bottom: 50px;
        justify-content: flex-start;
        min-height: calc(100vh - 60px);
    }
}

p, li, h5 {
    color: #222;
}

a {
    text-decoration: none;
    color: #222;
    scroll-margin-top: 6em;
}

p>a, h5>a, h6>a, span>a {
    text-decoration: underline dotted 1px;
    text-underline-offset: 3px;
    color: #222;
    scroll-margin-top: 6em;
}

p>a:hover, h5>a:hover, h6>a:hover, span>a:hover, li>a:hover {
    color: #49613f;
}

div{
    scroll-margin-top: 6em;
}

.container {
    max-width: 50em;
}

.divider {
    border-bottom: 1px solid #eaecef;
    margin: 1em 0;
}

.footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    line-height: 20px;
    z-index: 50; /* Ensure footer stays above content but below modals */
    background: inherit; /* Ensure footer has proper background */
}

h1,
h2,
h3 {
    color: #49613f !important;
}

h5{
    scroll-margin-top: 6em;
}

#nav-link,
#top-button {
    opacity: 0;
    transition: cubic-bezier(0.165, 0.84, 0.44, 1) 0.3s;
}

.list-dashed{
    list-style-type: "- ";
    margin-left: 0.5em !important;
    padding-left: 0.5em !important;
}

.box-link, .box-construct-link, .box-danger-link{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 0.5em 1em;
    border-radius: 0.5em;
    border: 1px solid #898b8d;
    margin: 0.2em 0;
    transition: cubic-bezier(0.165, 0.84, 0.44, 1) 0.3s;
}

.box-link:hover{
    background-color: #49613f;
    border: 1px solid #49613f;
    color: #fff;
}

.box-construct-link:hover{
    background-color: #7c7408;
    border: 1px solid #7c7408;
    color: #fff;
}

.box-danger-link:hover{
    background-color: #ac1a1a;
    border: 1px solid #ac1a1a;
    color: #fff;
}

.nav-header-bar{
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
}

.bg-navy{
    background-color: #49613f;
    color: #fff;
}

.text-bg-orange{
    background-color: #dd890c;
    color: #fff;
}

.text-bg-purple{
    background-color: #7c0869;
    color: #fff;
}

.text-bg-pink{
    background-color: #ac5454;
    color: #fff;
}

a.hover{
    background-color: #fff;
    transition: cubic-bezier(0.165, 0.84, 0.44, 1) 0.7s;
}

a.hover:hover{
    background-color: #49613f;
    color: #fff !important;
}

a.disabled{
    pointer-events: none;
    cursor: default;
}

.text-strikethrough{
    text-decoration: line-through;
}

img{
    scroll-margin-top: 6em;
}

/* Gallery lazy loading optimizations */
.image-container {
    position: relative;
    overflow: hidden;
    background-color: #f5f5f5;
    border-radius: 0.375rem;
}

.lazy-image:not(.modal-image):not(#modalImage) {
    filter: blur(2px);
    transition: filter 0.3s ease;
}

.lazy-image.loaded {
    filter: none !important;
}

/* Ensure loaded images don't have blur */
.loaded {
    filter: none !important;
}

/* Modal images should never be blurred */
#modalImage,
.modal-image {
    filter: none !important;
}

/* Override any lazy loading blur for modal */
.image-modal .modal-image.lazy-image {
    filter: none !important;
}

.lazy-image.error {
    filter: grayscale(100%);
    opacity: 0.7;
}

.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    z-index: 1;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #49613f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Image loading states */
.image-container img {
    transition: opacity 0.3s ease, transform 0.2s ease;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.image-container:hover img {
    transform: scale(1.02);
}

/* Prevent layout shift during image loading */
.image-container img[width][height] {
    height: auto;
    aspect-ratio: attr(width) / attr(height);
}

/* Responsive image optimization */
@media (max-width: 768px) {
    .image-container img {
        width: 100%;
        height: auto;
    }
}

/* Image Modal Styles */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    isolation: isolate;
}

.image-modal.modal-active {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1;
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: scale(0.8);
    transition: transform 0.3s ease;
    z-index: 100;
}

.image-modal.modal-active .modal-content {
    transform: scale(1);
}

.modal-close {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.8);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10000;
    transition: background-color 0.2s ease;
    font-size: 18px;
    color: white;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.modal-close::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.modal-close:active::before {
    width: 80px;
    height: 80px;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 1);
}

.modal-nav {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 20px;
    color: #333;
    overflow: hidden;
    position: relative;
}

.modal-nav::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
}

.modal-nav:active::before {
    width: 100px;
    height: 100px;
}

.modal-nav:hover {
    background: rgba(255, 255, 255, 1);
}

.modal-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* Bottom navigation bar */
.modal-nav-bar {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 280px;
    max-width: 90vw;
    z-index: 300;
    background: rgba(0, 0, 0, 0.85);
    padding: 12px 16px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.modal-toolbar-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    color: white;
    text-align: center;
    flex: 1;
    margin: 0 12px;
}

.modal-toolbar-info .modal-counter {
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    backdrop-filter: blur(10px);
    color: white;
}

.modal-toolbar-info .modal-title {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.9;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.modal-toolbar-info .instruction-text {
    font-size: 10px;
    font-weight: 400;
    opacity: 0.6;
    color: white;
    white-space: nowrap;
    margin-top: 2px;
    text-align: center;
}

.modal-prev,
.modal-next {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    transform: none;
}

.modal-image-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    z-index: 150;
    isolation: isolate;
}

.modal-image {
    max-width: 85vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
    transition: opacity 0.3s ease;
    z-index: 150;
    position: relative;
    filter: none !important;
}

.modal-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 8px;
}

.modal-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #49613f;
    border-radius: 50%;
    animation: modalSpin 1s linear infinite;
}

@keyframes modalSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}



/* Mobile optimizations */
@media (max-width: 768px) {
    .modal-content {
        max-width: 95vw;
        max-height: 95vh;
    }
    
    .modal-image {
        max-width: 90vw;
        max-height: 75vh;
    }
    
    .modal-close {
        top: 15px;
        right: 15px;
        width: 35px;
        height: 35px;
        font-size: 16px;
    }
    
    .modal-nav {
        width: 45px;
        height: 45px;
        font-size: 18px;
        background: rgba(255, 255, 255, 0.9);
        color: #333;
        overflow: hidden;
        position: relative;
    }
    
    .modal-nav-bar {
        bottom: 15px;
        padding: 10px 14px;
        min-width: 260px;
    }
    
    .modal-toolbar-info {
        margin: 0 8px;
    }
    
    .modal-toolbar-info .modal-title {
        max-width: 150px;
        font-size: 13px;
    }
    
    /* Change instruction text for tablet */
    .modal-toolbar-info .instruction-text {
        font-size: 0; /* Hide original text */
        max-width: 180px;
    }
    
    .modal-toolbar-info .instruction-text::after {
        content: "Swipe or use buttons • Tap background to close";
        font-size: 9px;
    }
}

@media (max-width: 480px) {
    .modal-content {
        max-width: 98vw;
        max-height: 98vh;
    }
    
    .modal-image {
        max-width: 85vw;
        max-height: 70vh;
    }
    
    .modal-close {
        top: 10px;
        right: 10px;
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .modal-nav {
        width: 40px;
        height: 40px;
        font-size: 16px;
        background: rgba(255, 255, 255, 0.9);
        color: #333;
        overflow: hidden;
        position: relative;
    }
    
    .modal-nav-bar {
        bottom: 10px;
        padding: 8px 12px;
        min-width: 240px;
    }
    
    .modal-toolbar-info {
        margin: 0 6px;
    }
    
    .modal-toolbar-info .modal-title {
        max-width: 120px;
        font-size: 12px;
    }
    
    .modal-toolbar-info .modal-counter {
        font-size: 12px;
        padding: 3px 8px;
    }
    
    .modal-toolbar-info .modal-title {
        max-width: 120px;
        font-size: 12px;
    }
    
    .modal-toolbar-info .instruction-text {
        font-size: 0; /* Hide original text */
        max-width: 160px;
    }
    
    .modal-toolbar-info .instruction-text::after {
        content: "Swipe or tap buttons";
        font-size: 8px;
    }
    
    /* Make buttons more visible on very small screens */
    .modal-nav:hover {
        background: rgba(255, 255, 255, 1);
    }
}

/* Touch-friendly hover states for mobile */
@media (hover: none) and (pointer: coarse) {
    .modal-nav:active {
        background: rgba(255, 255, 255, 1) !important;
    }
    
    .modal-close:active {
        background: rgba(0, 0, 0, 1) !important;
    }
    

    

}

/* Gallery image container cursor pointer */
.image-container {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.image-container:hover {
    transform: scale(1.02);
}

.image-container:active {
    transform: scale(0.98);
}

/* PDF Filter Section Styles */
.filter-section {
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
}

.filter-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.filter-header:hover {
    color: #dc3545;
}

.filter-content {
    transition: all 0.3s ease;
    overflow: hidden;
}

.filter-content.collapsed {
    max-height: 0;
    margin-bottom: 0;
    opacity: 0;
}

.collapse-icon {
    transition: transform 0.3s ease;
}

.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.filter-tag {
    border: 1px solid #dee2e6;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    user-select: none;
    width: 140px;
    height: 38px;
    text-align: center;
    background-color: white;
    color: #495057;
}

.filter-tag:hover {
    background-color: #f8f9fa;
    border-color: #adb5bd;
    color: #212529;
}

.filter-tag.active {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: white;
}

.filter-tag.active .count {
    background: rgba(255,255,255,0.2) !important;
    color: white !important;
}

.filter-tag .count {
    background: #e9ecef;
    color: #495057;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 12px;
    margin-left: 4px;
    font-weight: 600;
}

.filter-counter {
    font-weight: normal;
}

/* File list item filtering */
.list-group-item.filtered-out {
    display: none;
}

.semester-section.filtered-out {
    display: none;
}

/* Empty state */
.filter-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
    font-style: italic;
}

/* Logic toggle */
.logic-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    background-color: #e9ecef;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.logic-option {
    padding: 4px 12px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #6c757d;
    user-select: none;
}

.logic-option.active {
    background-color: #0d6efd;
    color: white;
}

.filter-counter {
    font-size: 14px !important;
    font-weight: 400;
}

/* Clean mobile interface */
@media (hover: none) and (pointer: coarse) {
    

    
    /* Mobile ripple effects */
    .modal-nav::before {
        background: rgba(0, 0, 0, 0.1);
    }
    
    .modal-nav:active::before {
        background: rgba(0, 0, 0, 0.2);
    }
    
    .modal-close:active::before {
        background: rgba(255, 255, 255, 0.3);
    }
}