/* ===================================
   CSS Variables - 全域變數
   =================================== */
:root {
    /* Colors */
    --color-pink: #FFA6D2;
    --color-blue: #009FE0;
    --color-green: #46B036;
    --color-yellow: #FFF001;
    --color-orange: #EE9601;
    --color-sky-blue: #87CEEB;
    
    /* Spacing */
    --container-max-width: 1400px;
    --container-padding: 40px;
    
    /* Transitions */
    --transition-smooth: 0.4s ease;
    --transition-cubic: cubic-bezier(0.4, 0, 0.2, 1);
}


/* ===================================
   1. LOADING SCREEN
   =================================== */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f0f0f0;
    border-top-color: var(--color-sky-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}


/* ===================================
   2. CONTAINER & LAYOUT
   =================================== */
.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--container-padding);
}


/* ===================================
   3. PAGE TITLE SECTION
   =================================== */
.works-title-section {
    display: flex;
    flex-direction: column;
    padding: 60px 40px 40px;
    margin-top: 15%;
    margin-bottom: 20px;
    text-align: left;
    max-width: var(--container-max-width);
    margin-left: auto;
    margin-right: auto;
    position: relative;
    overflow: hidden;
}

/* Background decorative number */
.works-title-section::before {
    content: '02';
    position: absolute;
    top: -20px;
    right: 10px;
    font-size: 250px;
    font-weight: 800;
    color: #f0f0f0;
    z-index: -1;
    line-height: 1;
}

.works-title {
    font-size: clamp(60px, 10vw, 120px);
    font-weight: 800;
    letter-spacing: 0.05em;
    margin-bottom: 20px;
    line-height: 1;
    color: var(--color-pink);
    transition: all var(--transition-smooth);
}

.works-title:hover {
    letter-spacing: 0.1em;
}

.works-subtitle {
    font-size: clamp(12px, 2vw, 20px);
    color: #666;
    font-weight: 100;
    text-align: left;
    line-height: 1.4;
}


/* ===================================
   4. MASONRY GRID SECTION
   =================================== */
.masonry-section {
    margin: 0 0 100px 0;
    padding: 0;
    width: 100vw;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

.masonry-grid {
    column-count: 4;
    column-gap: 20px;
}

.masonry-item {
    break-inside: avoid;
    margin-bottom: 20px;
    border-radius: 0;
    overflow: visible;
    position: relative;
    transition: transform 0.3s var(--transition-cubic);
    display: inline-block;
    width: 100%;
}

/* Image Container */
.masonry-image {
    width: 100%;
    position: relative;
    display: inline-block;
    overflow: visible;
}

.masonry-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    opacity: 0;
    transition: opacity 0.5s ease;
    z-index: 1;
}

.masonry-image img.loaded {
    opacity: 1;
    animation: imageFadeIn 1s var(--transition-cubic) forwards;
}

/* Hover Effect - Rotate Container */
.masonry-item:hover .masonry-image {
    transform: rotate(var(--rotate-angle, 0deg));
    transition: transform var(--transition-smooth) cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.masonry-item:hover .masonry-image img {
    opacity: 0.1;
    transition: opacity 0.5s ease;
}

/* Color Mask Overlay */
.masonry-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bird-color);
    opacity: 0;
    transition: opacity var(--transition-smooth);
    z-index: 2;
    pointer-events: none;
    mask-image: var(--mask-image);
    -webkit-mask-image: var(--mask-image);
    mask-size: contain;
    -webkit-mask-size: contain;
    mask-repeat: no-repeat;
    -webkit-mask-repeat: no-repeat;
    mask-position: center;
    -webkit-mask-position: center;
}

.masonry-item:hover .masonry-image::before {
    opacity: 0.6;
    transition: opacity var(--transition-smooth);
}


/* ===================================
   5. COLOR ASSIGNMENTS (Cycle of 5)
   =================================== */
.masonry-item:nth-child(5n+1) { --bird-color: var(--color-pink); }
.masonry-item:nth-child(5n+2) { --bird-color: var(--color-blue); }
.masonry-item:nth-child(5n+3) { --bird-color: var(--color-green); }
.masonry-item:nth-child(5n+4) { --bird-color: var(--color-yellow); }
.masonry-item:nth-child(5n) { --bird-color: var(--color-orange); }


/* ===================================
   6. RANDOM ROTATION ANGLES (Cycle of 20)
   =================================== */
.masonry-item:nth-child(20n+1) { --rotate-angle: 8deg; }
.masonry-item:nth-child(20n+2) { --rotate-angle: -5deg; }
.masonry-item:nth-child(20n+3) { --rotate-angle: 12deg; }
.masonry-item:nth-child(20n+4) { --rotate-angle: -8deg; }
.masonry-item:nth-child(20n+5) { --rotate-angle: 6deg; }
.masonry-item:nth-child(20n+6) { --rotate-angle: -10deg; }
.masonry-item:nth-child(20n+7) { --rotate-angle: 9deg; }
.masonry-item:nth-child(20n+8) { --rotate-angle: -7deg; }
.masonry-item:nth-child(20n+9) { --rotate-angle: 11deg; }
.masonry-item:nth-child(20n+10) { --rotate-angle: -6deg; }
.masonry-item:nth-child(20n+11) { --rotate-angle: 7deg; }
.masonry-item:nth-child(20n+12) { --rotate-angle: -9deg; }
.masonry-item:nth-child(20n+13) { --rotate-angle: 10deg; }
.masonry-item:nth-child(20n+14) { --rotate-angle: -11deg; }
.masonry-item:nth-child(20n+15) { --rotate-angle: 8deg; }
.masonry-item:nth-child(20n+16) { --rotate-angle: -12deg; }
.masonry-item:nth-child(20n+17) { --rotate-angle: 6deg; }
.masonry-item:nth-child(20n+18) { --rotate-angle: -8deg; }
.masonry-item:nth-child(20n+19) { --rotate-angle: 9deg; }
.masonry-item:nth-child(20n) { --rotate-angle: -7deg; }


/* ===================================
   7. RANDOM HEIGHTS (Cycle of 20)
   =================================== */
.masonry-item:nth-child(20n+1) .masonry-image { padding-top: 60%; }
.masonry-item:nth-child(20n+2) .masonry-image { padding-top: 120%; }
.masonry-item:nth-child(20n+3) .masonry-image { padding-top: 75%; }
.masonry-item:nth-child(20n+4) .masonry-image { padding-top: 140%; }
.masonry-item:nth-child(20n+5) .masonry-image { padding-top: 85%; }
.masonry-item:nth-child(20n+6) .masonry-image { padding-top: 110%; }
.masonry-item:nth-child(20n+7) .masonry-image { padding-top: 65%; }
.masonry-item:nth-child(20n+8) .masonry-image { padding-top: 115%; }
.masonry-item:nth-child(20n+9) .masonry-image { padding-top: 90%; }
.masonry-item:nth-child(20n+10) .masonry-image { padding-top: 70%; }
.masonry-item:nth-child(20n+11) .masonry-image { padding-top: 130%; }
.masonry-item:nth-child(20n+12) .masonry-image { padding-top: 80%; }
.masonry-item:nth-child(20n+13) .masonry-image { padding-top: 105%; }
.masonry-item:nth-child(20n+14) .masonry-image { padding-top: 72%; }
.masonry-item:nth-child(20n+15) .masonry-image { padding-top: 125%; }
.masonry-item:nth-child(20n+16) .masonry-image { padding-top: 78%; }
.masonry-item:nth-child(20n+17) .masonry-image { padding-top: 135%; }
.masonry-item:nth-child(20n+18) .masonry-image { padding-top: 95%; }
.masonry-item:nth-child(20n+19) .masonry-image { padding-top: 100%; }
.masonry-item:nth-child(20n) .masonry-image { padding-top: 88%; }


/* ===================================
   8. FILTER CONTROLS
   =================================== */
.filter-controls {
    padding: 30px;
    border-radius: 8px;
    margin-bottom: 40px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Search Input */
.filter-group.search-filter {
    position: relative;
    margin-bottom: 30px;
}

.filter-group.search-filter input {
    width: 100%;
    padding: 12px 40px 12px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.filter-group.search-filter input:focus {
    border-color: var(--color-sky-blue);
    transform: scale(1.01);
}

/* Clear Button */
.filter-group.search-filter .clear-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    z-index: 10;
    transition: all 0.2s ease;
}

.filter-group.search-filter .clear-btn:hover {
    background: #f0f0f0;
    color: #666;
}

/* Filter Groups */
.filter-group {
    padding: 24px 0;
    border-bottom: 1px solid #e0e0e0;
}

.filter-title {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 20px;
    color: #333;
}

.filter-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px 20px;
}

/* Custom Checkbox Styling */
.filter-options label {
    position: relative;
    cursor: pointer;
    font-size: 14px;
    color: #555;
    user-select: none;
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding-left: 32px;
    transition: color 0.2s ease;
}

.filter-options input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    height: 0;
    width: 0;
    cursor: pointer;
}

/* Custom Checkbox Box */
.filter-options label:before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border: 2px solid #ccc;
    border-radius: 6px;
    background-color: #fafafa;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Custom Checkmark */
.filter-options label:after {
    content: '';
    position: absolute;
    left: 8px;
    top: 50%;
    width: 6px;
    height: 12px;
    border: solid white;
    border-width: 0 3px 3px 0;
    transform: translateY(-60%) rotate(45deg) scale(0);
    opacity: 0;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Checked State */
.filter-options label:has(input[type="checkbox"]:checked):before {
    background-color: var(--color-sky-blue);
    border-color: var(--color-sky-blue);
    transform: translateY(-50%) scale(1.05);
    animation: checkboxPop 0.3s ease;
}

.filter-options label:has(input[type="checkbox"]:checked):after {
    opacity: 1;
    transform: translateY(-60%) rotate(45deg) scale(1);
}

.filter-options label:has(input[type="checkbox"]:checked) {
    color: #333;
    font-weight: 500;
}

/* Hover Effect */
.filter-options label:hover:before {
    border-color: var(--color-sky-blue);
}

/* Clear All Button */
.filter-group.actions {
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
    margin-top: 20px;
    border-bottom: none;
    position: relative;
    z-index: 1;
}

.clear-all-btn {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 18px 50px;
    background: #333;
    color: #fafafa;
    border: none;
    font-size: 16px;
    font-weight: 400;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 10px;
}

.clear-all-btn:hover {
    background: var(--color-pink);
    transform: translateY(-2px);
}

.clear-all-btn:active {
    transform: translateY(0);
}


/* ===================================
   9. WORKS GRID (Alternative Layout)
   =================================== */
.works-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 30px;
    margin-bottom: 60px;
    justify-content: center;
    align-content: start;
}

.work-item {
    border-radius: 2px;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}

.work-item a {
    text-decoration: none;
    color: inherit;
    display: block;
}

.work-image {
    width: 100%;
    padding-top: 75%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: transform var(--transition-smooth);
}

.work-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: auto;
    margin: 10px;
    object-fit: cover;
    display: block;
    opacity: 0;
    transition: opacity 0.5s ease, transform var(--transition-smooth);
}

.work-image img:hover {
    transform: scale(1.05);
}

.work-image img.loaded {
    opacity: 1;
}

.work-info {
    padding: 15px;
}

.work-info .work-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #222;
    margin-bottom: 5px;
    line-height: 1.5;
}


/* ===================================
   10. EMPTY STATES
   =================================== */
.no-works-state {
    text-align: center;
    padding: 120px 20px;
    min-height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.no-works-content h2 {
    font-size: 2.5rem;
    color: var(--color-pink);
    margin-bottom: 20px;
    font-weight: 600;
    letter-spacing: 0.1em;
}

.no-works-content p {
    font-size: 1.2rem;
    color: #999;
    font-weight: 300;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    font-size: 1.1rem;
}


/* ===================================
   11. ANIMATIONS
   =================================== */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes imageFadeIn {
    0% {
        opacity: 0;
        transform: translateY(10px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes checkboxPop {
    0% { transform: translateY(-50%) scale(0.9); }
    50% { transform: translateY(-50%) scale(1.08); }
    100% { transform: translateY(-50%) scale(1.05); }
}

/* Progressive Loading Animation Delays */
.masonry-item:nth-child(1) .masonry-image img.loaded { animation-delay: 0.1s; }
.masonry-item:nth-child(2) .masonry-image img.loaded { animation-delay: 0.2s; }
.masonry-item:nth-child(3) .masonry-image img.loaded { animation-delay: 0.3s; }
.masonry-item:nth-child(4) .masonry-image img.loaded { animation-delay: 0.4s; }
.masonry-item:nth-child(5) .masonry-image img.loaded { animation-delay: 0.5s; }


/* ===================================
   12. ACCESSIBILITY
   =================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    * {
        will-change: auto !important;
    }
}

@media (prefers-reduced-data: reduce) {
    .masonry-image img,
    .work-image img {
        image-rendering: auto;
    }
}


/* ===================================
   13. RESPONSIVE DESIGN - TABLET
   =================================== */
@media (max-width: 1024px) {
    .container {
        padding: 0 30px;
    }

    .masonry-grid {
        column-count: 3;
        column-gap: 15px;
    }
    
    .masonry-item {
        margin-bottom: 15px;
    }

    .filter-controls {
        padding: 25px;
    }

    .filter-options {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px 15px;
    }

    .filter-title {
        font-size: 1.1rem;
    }

    .filter-group.search-filter input {
        padding: 10px 40px 10px 12px;
        font-size: 0.95rem;
    }

    .works-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 25px;
    }
}


/* ===================================
   14. RESPONSIVE DESIGN - MOBILE
   =================================== */
@media (max-width: 768px) {
    .container {
        padding: 0 20px;
    }

    .works-title-section {
        padding: 40px 20px 30px;
        margin-top: 15vh;
        margin-bottom: 10px;
    }

    .works-title {
        -webkit-text-stroke-width: 1.5px;
        line-height: 1.1;
    }

    .no-works-state {
        padding: 80px 20px;
    }
    
    .no-works-content h2 {
        font-size: 2rem;
    }
    
    .no-works-content p {
        font-size: 1rem;
    }

    .masonry-section {
        margin-bottom: 60px;
    }

    .masonry-grid {
        column-count: 3;
        column-gap: 12px;
    }
    
    .masonry-item {
        margin-bottom: 12px;
    }

    /* Mobile Random Heights */
    .masonry-item:nth-child(20n+1) .masonry-image { padding-top: 55%; }
    .masonry-item:nth-child(20n+2) .masonry-image { padding-top: 110%; }
    .masonry-item:nth-child(20n+3) .masonry-image { padding-top: 70%; }
    .masonry-item:nth-child(20n+4) .masonry-image { padding-top: 125%; }
    .masonry-item:nth-child(20n+5) .masonry-image { padding-top: 80%; }
    .masonry-item:nth-child(20n+6) .masonry-image { padding-top: 100%; }
    .masonry-item:nth-child(20n+7) .masonry-image { padding-top: 60%; }
    .masonry-item:nth-child(20n+8) .masonry-image { padding-top: 105%; }
    .masonry-item:nth-child(20n+9) .masonry-image { padding-top: 85%; }
    .masonry-item:nth-child(20n+10) .masonry-image { padding-top: 65%; }
    .masonry-item:nth-child(20n+11) .masonry-image { padding-top: 115%; }
    .masonry-item:nth-child(20n+12) .masonry-image { padding-top: 75%; }
    .masonry-item:nth-child(20n+13) .masonry-image { padding-top: 95%; }
    .masonry-item:nth-child(20n+14) .masonry-image { padding-top: 68%; }
    .masonry-item:nth-child(20n+15) .masonry-image { padding-top: 108%; }
    .masonry-item:nth-child(20n+16) .masonry-image { padding-top: 72%; }
    .masonry-item:nth-child(20n+17) .masonry-image { padding-top: 118%; }
    .masonry-item:nth-child(20n+18) .masonry-image { padding-top: 88%; }
    .masonry-item:nth-child(20n+19) .masonry-image { padding-top: 92%; }
    .masonry-item:nth-child(20n) .masonry-image { padding-top: 82%; }

    /* Filter Optimization */
    .filter-controls {
        padding: 20px;
        margin-bottom: 30px;
    }

    .filter-group {
        padding: 20px 0;
    }

    .filter-group.search-filter {
        margin-bottom: 25px;
    }

    .filter-title {
        font-size: 1rem;
        margin-bottom: 15px;
    }

    .filter-group.search-filter input {
        padding: 10px 35px 10px 12px;
        font-size: 0.9rem;
        border-radius: 6px;
    }

    .filter-group.search-filter .clear-btn {
        right: 8px;
        width: 28px;
        height: 28px;
        font-size: 20px;
    }

    /* 2 Column Checkboxes */
    .filter-options {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px 12px;
    }

    .filter-options label {
        font-size: 13px;
        padding-left: 28px;
    }

    .filter-options label:before {
        width: 20px;
        height: 20px;
    }

    .filter-options label:after {
        left: 7px;
        width: 5px;
        height: 10px;
        border-width: 0 2px 2px 0;
    }

    .filter-group.actions {
        padding-top: 15px;
        margin-top: 15px;
    }

    .clear-all-btn {
        width: 100%;
        padding: 14px 24px;
        font-size: 0.9rem;
    }

    /* Simplified Animations */
    .masonry-item:hover .masonry-image {
        transform: none;
    }
    
    .masonry-item:hover .masonry-image::before {
        opacity: 0.8;
    }
    
    .work-image img:hover {
        transform: scale(1.02);
    }

    .works-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 20px;
    }

    .work-info .work-title {
        font-size: 1rem;
    }

    .work-info .work-author {
        font-size: 0.85rem;
    }
}


/* ===================================
   15. RESPONSIVE DESIGN - SMALL MOBILE
   =================================== */
@media (max-width: 480px) {
    .container {
        padding: 0 15px;
    }

    .works-title-section::before {
        display: none;
    }

    .works-title {
        font-size: clamp(50px, 15vw, 80px);
        -webkit-text-stroke-width: 1px;
        letter-spacing: 0.02em;
    }

    .works-title:hover {
        letter-spacing: 0.05em;
    }

    .works-subtitle {
        font-size: clamp(14px, 4vw, 18px);
    }

    .no-works-content h2 {
        font-size: 1.5rem;
    }

    .masonry-grid {
        column-count: 3;
        column-gap: 10px;
    }

    .masonry-item {
        margin-bottom: 10px;
    }

    /* Disable All Hover Effects */
    .masonry-item:hover .masonry-image {
        transform: none;
    }
    
    .masonry-item:hover .masonry-image::before {
        opacity: 0;
    }
    
    /* Single Column Filters */
    .filter-controls {
        padding: 15px;
        border-radius: 6px;
        margin-bottom: 25px;
    }

    .filter-group {
        padding: 15px 0;
    }

    .filter-group.search-filter {
        margin-bottom: 20px;
    }

    .filter-title {
        font-size: 0.95rem;
        margin-bottom: 12px;
    }

    .filter-group.search-filter input {
        padding: 9px 32px 9px 10px;
        font-size: 0.85rem;
    }

    /* Single Column Checkboxes */
    .filter-options {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .filter-options label {
        font-size: 12px;
        min-height: 20px;
        padding-left: 26px;
    }

    .filter-options label:before {
        width: 18px;
        height: 18px;
        border-width: 1.5px;
    }

    .filter-options label:after {
        left: 6px;
        width: 4px;
        height: 9px;
        border-width: 0 2px 2px 0;
    }

    .clear-all-btn {
        padding: 12px 20px;
        font-size: 0.85rem;
    }

    .works-grid {
        grid-template-columns: 1fr;
        gap: 15px;}

    .work-image {
        padding-top: 65%;
    }

    .work-image img:hover {
        transform: none;
    }

    .empty-state {
        padding: 60px 15px;
        font-size: 1rem;
    }
}