/* PP Neue Montreal Font */
@font-face {
    font-family: "PP Neue Montreal";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: local("PP Neue Montreal"),
        url("https://fonts.cdnfonts.com/s/100431/ppneuemontreal-book.woff") format("woff");
}

@font-face {
    font-family: "PP Neue Montreal";
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: local("PP Neue Montreal"),
        url("https://fonts.cdnfonts.com/s/100431/ppneuemontreal-italic.woff") format("woff");
}

@font-face {
    font-family: "PP Neue Montreal";
    font-style: normal;
    font-weight: 100;
    font-display: swap;
    src: local("PP Neue Montreal"),
        url("https://fonts.cdnfonts.com/s/100431/ppneuemontreal-thin.woff") format("woff");
}

@font-face {
    font-family: "PP Neue Montreal";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: local("PP Neue Montreal"),
        url("https://fonts.cdnfonts.com/s/100431/ppneuemontreal-medium.woff") format("woff");
}

@font-face {
    font-family: "PP Neue Montreal";
    font-style: italic;
    font-weight: 600;
    font-display: swap;
    src: local("PP Neue Montreal"),
        url("https://fonts.cdnfonts.com/s/100431/ppneuemontreal-semibolditalic.woff") format("woff");
}

@font-face {
    font-family: "PP Neue Montreal";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: local("PP Neue Montreal"),
        url("https://fonts.cdnfonts.com/s/100431/ppneuemontreal-bold.woff") format("woff");
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --padding: 2rem;
    --gutter: 0.75rem;
    /* Reduced spacing between lines */
    --columns: 12;
    /* Dark Theme (Default) */
    --bg-color: #0a0a0a;
    --text-color: #e0e0e0;
    --accent-color: #ffc700;
    --grid-color: rgba(255, 255, 255, 0.15);
    --border-color: rgba(255, 255, 255, 0.1);
    --surface-color: rgba(255, 255, 255, 0.03);
    --surface-hover-color: rgba(255, 255, 255, 0.08);
    --row-spacing: 4rem;
}

/* Light Theme */
[data-theme="light"] {
    --bg-color: #f8f8f8;
    --text-color: #1a1a1a;
    --accent-color: #f5b700;
    --grid-color: rgba(0, 0, 0, 0.1);
    --border-color: rgba(0, 0, 0, 0.1);
    --surface-color: rgba(0, 0, 0, 0.03);
    --surface-hover-color: rgba(0, 0, 0, 0.08);
}

html, body {
    min-height: 100%;
}

body {
    font-family: "PP Neue Montreal", sans-serif;
    font-weight: 500;
    font-size: 16px;
    letter-spacing: -0.03em;
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: var(--padding);
    overflow-x: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex-grow: 1;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(var(--columns), 1fr);
    gap: var(--gutter);
    row-gap: var(--row-spacing);
    width: 100%;
    /* Use 100% width instead of fixed max-width */
    margin: 0 auto;
    position: relative;
}

/* Grid overlay */
.grid-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: var(--padding);
    pointer-events: none;
    z-index: 1000;
}

.grid-overlay-inner {
    display: grid;
    grid-template-columns: repeat(var(--columns), 1fr);
    gap: var(--gutter);
    height: 100%;
    width: 100%;
    /* Match the grid container width */
    margin: 0 auto;
}

.grid-column {
    height: 100%;
    border-left: 1px solid var(--grid-color);
    border-right: 1px solid var(--grid-color);
    border-top: none;
    border-bottom: none;
    opacity: 0;
}

/* Header aligned with grid */
.header {
    display: grid;
    grid-template-columns: repeat(var(--columns), 1fr);
    gap: var(--gutter);
    margin-bottom: 6rem;
    align-items: center;
}

.logo {
    grid-column: 1 / span 3;
    font-weight: 700;
    font-size: 2rem;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.logo img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.nav {
    grid-column: 7 / span 6;
    display: flex;
    justify-content: flex-end;
    gap: 2.5rem;
    align-items: center;
}

.nav-item {
    font-size: 1.5rem;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.05em;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
}

.nav-item:hover {
    opacity: 1;
}

/* 活動頁面樣式 */
.nav-item.active {
    background: rgba(255, 199, 0, 0.1);
    border: 1px solid rgba(255, 199, 0, 0.2);
}

.nav-item.active a {
    color: #ffffff !important;
    text-shadow: 0 0 10px rgba(255, 199, 0, 0.3);
}

/* 導航連結樣式 */
.nav-item a {
    color: var(--text-color);
    text-decoration: none;
    display: block;
    transition: all 0.3s ease;
}

.nav-item a:hover {
    color: #fff;
}

.hamburger {
    display: none;
}

.inversion-lens {
    position: relative;
    overflow: hidden;
    background-color: transparent; /* 移除黑色背景，讓圖片直接顯示在頁面上 */
    z-index: 1;
    will-change: transform, opacity; /* 優化動畫性能 */
    /* Set z-index for stacking */
}

.inversion-lens img {
    display: block;
    width: 100%;
    height: auto;
    position: relative;
    z-index: 0;
}

.inversion-lens canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Canvas 疊加在圖片上方，圖片保持可見以撐開容器 */
.inversion-lens.webgl-active img {
    /* 不再隱藏圖片，讓它撐開容器高度 */
}

.project-info {
    font-size: 1rem;
    margin-top: 1rem;
    line-height: 1.2;
    position: relative;
    will-change: transform; /* 優化視差動畫性能 */
    /* Allow for positioning with GSAP */
    z-index: 2;
    /* Ensure text is above the image */
}

.project-date {
    font-size: 1rem;
    text-transform: uppercase;
    margin-bottom: 0.1rem;
}

.project-title {
    font-weight: 700;
    font-size: 2rem;
    margin-top: 0.125rem;
    text-transform: uppercase;
}

.project-subtitle {
    margin-top: 0.125rem;
    font-size: 1rem;
}

/* 作品日期懸停顯示 */
.project-date-hover {
    font-size: 0.9rem;
    color: var(--accent-color);
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 199, 0, 0.2);
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
}

/* 當滑鼠懸停在 project-info 上時顯示日期 */
.project-info:hover .project-date-hover {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* 確保所有圖文區塊容器都有相對定位，以便內部絕對定位的元素能正確對齊 */
[class*="item-"][class*="container"] {
    position: relative;
}

/* 確保所有圖文區塊容器內的內容都向上對齊，解決動態載入項目文字與圖片間距過大的問題 */
[class*="item-"][class*="container"] {
    align-self: start;
}

/* --- DESKTOP-ONLY GRID LAYOUT (min-width: 769px) --- */
/* 將所有桌面版的精確排版規則包裹起來，防止影響行動裝置 */
@media (min-width: 769px) {
    /* 項目 1 - 大型精選作品 */
    .item-1-container {
        grid-column: 2 / span 5;
        grid-row: auto;
    }

    /* 項目 2 */
    .item-2-container {
        grid-column: 8 / span 4;
        grid-row: auto;
    }

    /* 項目 3 */
    .item-3-container {
        grid-column: 3 / span 4;
        grid-row: auto;
        margin-top: var(--row-spacing);
    }

    /* 項目 4 */
    .item-4-container {
        grid-column: 8 / span 4;
        grid-row: auto;
    }

    /* 項目 5 - 精選作品 */
    .item-5-container {
        grid-column: 3 / span 4;
        grid-row: auto;
        margin-top: var(--row-spacing);
    }

    /* 項目 6 */
    .item-6-container {
        grid-column: 8 / span 4;
        grid-row: auto;
    }

    /* 項目 7 */
    .item-7-container {
        grid-column: 2 / span 4;
        grid-row: auto;
        margin-top: var(--row-spacing);
    }

    /* 項目 8 */
    .item-8-container {
        grid-column: 7 / span 4;
        grid-row: auto;
    }

    /* 項目 9 */
    .item-9-container {
        grid-column: 2 / span 4;
        grid-row: auto;
        margin-top: var(--row-spacing);
    }

    /* 項目 10 */
    .item-10-container {
        grid-column: 7 / span 4;
        grid-row: auto;
    }

    /* 項目 11 */
    .item-11-container {
        grid-column: 3 / span 4;
        grid-row: auto;
        margin-top: var(--row-spacing);
    }

    /* 項目 12 */
    .item-12-container {
        grid-column: 8 / span 4;
        grid-row: auto;
    }
}

.footer {
    text-align: left;
    padding: 2rem 0;
    margin-top: 4rem;
    font-size: 0.8rem;
    color: rgba(224, 224, 224, 0.5);
}

.nav-logo {
    display: none;
    font-weight: 700;
    font-size: 1.3rem;
    text-transform: uppercase;
    align-items: center;
    gap: 0.8rem;
    color: var(--text-color);
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
}

.nav-logo img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

@media (max-width: 768px) {
    :root {
        --padding: 1.5rem;
        --gutter: 0.8rem;
        /* 增加間距讓內容更透氣 */
        --row-spacing: 3.5rem;
        /* 增加行間距 */
    }

    body {
        font-size: 15px;
        padding: var(--padding);
    }

    .grid-container {
        grid-template-columns: repeat(4, 1fr);
        /* 使用4列而非6列，更適合平板 */
        gap: var(--gutter);
        row-gap: var(--row-spacing);
    }

    .grid-overlay-inner {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* 重新定義項目在平板上的位置 */
    .item-1-container {
        grid-column: 1 / span 4;
        /* grid-row: 1; */ /* 移除固定的行號，讓網格自動排列 */
    }

    .item-2-container {
        grid-column: 1 / span 2;
        /* grid-row: 2; */ /* 移除固定的行號 */
    }

    .item-3-container {
        grid-column: 3 / span 2;
        /* grid-row: 2; */ /* 移除固定的行號 */
    }

    .item-4-container {
        grid-column: 1 / span 4;
        /* grid-row: 3; */ /* 移除固定的行號 */
    }
    
    /* 其他項目 */
    .item-5-container,
    .item-6-container,
    .item-7-container,
    .item-8-container,
    .item-9-container,
    .item-10-container {
        grid-column: 1 / span 4;
    }

    .header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 3rem;
        grid-column: 1 / -1; /* Ensure header spans full width on mobile too */
    }

    .logo {
        font-size: 1.3rem;
    }
    
    .logo img {
        width: 28px;
        height: 28px;
    }

    /* Hamburger Menu Styles */
    .hamburger {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 2rem;
        height: 2rem;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        z-index: 1002;
    }

    .hamburger .line {
        width: 2rem;
        height: 2px;
        background-color: var(--text-color);
        transition: all 0.3s linear;
        position: relative;
        transform-origin: 1px;
    }

    .hamburger.is-active .line:nth-child(1) {
        transform: rotate(45deg);
    }

    .hamburger.is-active .line:nth-child(2) {
        opacity: 0;
        transform: translateX(20px);
    }

    .hamburger.is-active .line:nth-child(3) {
        transform: rotate(-45deg);
    }

    .nav {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: 100%;
        background-color: var(--bg-color);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2rem;
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1001;
    }

    .nav.is-active {
        transform: translateX(0);
    }

    .nav-item {
        font-size: 2rem;
        color: var(--text-color);
    }

    .nav.is-active .nav-logo {
        display: flex;
    }
}

@media (max-width: 480px) {
    :root {
        --padding: 1rem;
        --gutter: 0.6rem;
        /* 增加手機間距 */
        --row-spacing: 2rem;
        /* 調整行間距 */
    }

    body {
        font-size: 14px;
        padding: var(--padding);
    }

    .grid-container {
        grid-template-columns: 1fr;
        /* 單列直線排版 */
        gap: var(--gutter);
        row-gap: var(--row-spacing);
    }

    .grid-overlay-inner {
        grid-template-columns: 1fr;
    }

    .header {
        margin-bottom: 2.5rem;
        grid-column: 1 / -1;
    }

    .logo {
        font-size: 1.2rem;
    }
    
    .logo img {
        width: 24px;
        height: 24px;
    }

    .nav-item {
        font-size: 1.3rem;
        /* 稍微縮小以適應小螢幕 */
    }

    
    /* 手機版項目佈局 - 單列圖文重疊排版 */
    [class*="item-"][class*="container"] {
        grid-column: 1 / -1 !important; /* 新增：強制所有項目佔滿單欄，解決流動排列問題 */
        grid-row: auto !important; /* 新增：重置行定位，讓項目自動排列，解決重疊問題 */
        position: relative !important;
        margin-bottom: 2rem;
        width: 100%;
        /* 所有項目都佔滿單列寬度 */
    }

    /* 統一項目高度 - 單列圖文重疊排版 */
    [class*="item-"].inversion-lens {
        height: auto !important; /* 改為 auto，讓高度由圖片決定 */
        width: 100% !important;
        /* 增加高度以容納重疊文字 */
        border-radius: 0; /* 移除圓角 */
        overflow: hidden;
    }
    
    /* 在行動裝置上，確保圖片可見以撐開容器 */
    .inversion-lens img {
        display: block !important;
        width: 100%;
        height: auto;
    }

    /* 調整項目間距 */
    :root {
        --row-spacing: 2rem; /* 增加行間距，清楚分隔各項目 */
    }
    
    /* 行動版圖文重疊樣式 - 無背景 - 適用於所有project-info */
    .grid-container .project-info {
        position: absolute !important;
        bottom: 1rem !important;
        left: 1rem !important;
        right: 1rem !important;
        top: auto !important;
        z-index: 10 !important;
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
        border-radius: 0 !important;
        border: none !important;
        color: #ffffff !important;
        width: auto !important;
        height: auto !important;
        box-sizing: border-box !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.8) !important;
        transform: none !important; /* 防止變形動畫干擾定位 */
    }

    /* 手機版文字樣式調整 - 防止重疊 - 適用於所有project-info */
    .grid-container .project-date {
        font-size: 0.8rem !important;
        color: rgba(255, 255, 255, 0.8) !important;
        margin: 0 0 0.4rem 0 !important;
        padding: 0 !important;
        line-height: 1.3 !important;
        display: block !important;
    }

    .grid-container .project-title {
        font-size: 1.3rem !important;
        font-weight: 700 !important;
        margin: 0 0 0.4rem 0 !important;
        padding: 0 !important;
        color: #ffffff !important;
        text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8) !important;
        line-height: 1.2 !important;
        display: block !important;
    }

    .grid-container .project-subtitle {
        font-size: 0.85rem !important;
        color: rgba(255, 255, 255, 0.9) !important;
        margin: 0 !important;
        padding: 0 !important;
        line-height: 1.4 !important;
        display: block !important;
    }

    #settings-toggle-btn {
        top: 6rem;
    }
}

/* 超小螢幕優化 (小型手機) */
@media (max-width: 360px) {
    :root {
        --padding: 0.8rem;
        --gutter: 0.5rem;
        --row-spacing: 1.5rem;
    }
    
    .header {
        margin-bottom: 2rem;
    }
    
    .logo {
        font-size: 1.1rem;
    }
    
    .logo img {
        width: 20px;
        height: 20px;
    }
    
    /* 超小螢幕改為單列佈局 */
    .grid-container {
        grid-template-columns: 1fr;
    }
    
    .grid-overlay-inner {
        grid-template-columns: 1fr;
    }
    
    /* 所有項目佔滿寬度 */
    [class*="item-"][class*="container"] {
        grid-column: 1 / -1 !important;
        width: 100%;
        position: relative !important;
    }
    
    /* 統一較小的高度 - 超小螢幕圖文重疊 */
    [class*="item-"].inversion-lens {
        width: 100% !important;
        min-height: 40vh; /* 設定最小高度以防止塌陷 */
        border-radius: 0; /* 移除圓角 */
        background-color: transparent;
    } 
    
    /* 超小螢幕圖文重疊樣式 - 無背景 - 適用於所有project-info */
    .grid-container .project-info {
        position: absolute !important;
        bottom: 0.8rem !important;
        left: 0.8rem !important;
        right: 0.8rem !important;
        top: auto !important;
        z-index: 10 !important;
        margin: 0 !important;
        padding: 0 !important;
        background: none !important;
        border-radius: 0 !important;
        border: none !important;
        color: #ffffff !important;
        width: auto !important;
        height: auto !important;
        box-sizing: border-box !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.8) !important;
        transform: none !important; /* 防止變形動畫干擾定位 */
    }
    
    /* 超小螢幕文字尺寸調整 - 防止重疊 - 適用於所有project-info */
    .grid-container .project-title {
        font-size: 1.1rem !important;
        text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8) !important;
        margin: 0 0 0.3rem 0 !important;
        line-height: 1.2 !important;
    }
    
    .grid-container .project-date {
        font-size: 0.75rem !important;
        margin: 0 0 0.3rem 0 !important;
        line-height: 1.3 !important;
    }
    
    .grid-container .project-subtitle {
        font-size: 0.8rem !important;
        line-height: 1.4 !important;
        margin: 0 !important;
    }
}

/* Improved dat.gui styling */
.dg.ac {
    z-index: 1001 !important;
}

/* Settings Toggle Button - 移除浮動按鈕，將整合至導航 */
#settings-toggle-btn {
    display: none !important;
}

/* Theme Toggle Button - 移除浮動按鈕，將整合至導航 */
#theme-toggle-btn {
    display: none !important;
}

/* 導航圖標按鈕樣式 - 恢復正常外觀 */
.nav-icon-item {
    font-size: 1.2rem !important;
    cursor: pointer !important;
    user-select: none !important;
    border: 1px solid var(--text-color) !important;
    padding: 0.5rem !important;
    border-radius: 4px !important;
    transition: all 0.3s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 2.5rem !important;
    min-height: 2.5rem !important;
    width: 2.5rem !important;
    height: 2.5rem !important;
    visibility: visible !important;
    opacity: 1 !important;
    color: var(--text-color) !important;
    background: rgba(255, 255, 255, 0.1) !important;
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif !important;
    line-height: 1 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
    position: relative !important;
    z-index: 1010 !important;
    flex-shrink: 0 !important;
    font-weight: 500 !important;
}

/* 移除::before偽元素，現在使用實際文字內容 */

.nav-icon-item:hover {
    border-color: var(--accent-color) !important;
    background: rgba(255, 255, 255, 0.2) !important;
    transform: scale(1.05) !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3) !important;
}

/* 桌面版樣式重置 */
@media (min-width: 769px) {
    .hamburger {
        display: none !important;
    }
    
    .nav {
        position: relative !important;
        background: transparent !important;
        transform: none !important;
        height: auto !important;
        width: auto !important;
        flex-direction: row !important;
        justify-content: flex-end !important;
        align-items: center !important;
        gap: 2.5rem !important;
        z-index: auto !important;
    }
    
    .nav-item {
        font-size: 1.5rem !important;
        margin: 0 !important;
    }
    
    .nav-icon-item {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        font-size: 1.6rem !important;
        min-width: 2.8rem !important;
        min-height: 2.8rem !important;
        width: 2.8rem !important;
        height: 2.8rem !important;
        border-width: 2px !important;
        background: rgba(255, 255, 255, 0.2) !important;
        margin: 0 !important;
        padding: 0.4rem !important;
    }
}

/* Light模式下圖標顯示 */
[data-theme="light"] .nav-icon-item {
    color: #1a1a1a !important;
    border-color: #1a1a1a !important;
    background: rgba(0, 0, 0, 0.15) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

[data-theme="light"] .nav-icon-item:hover {
    background: rgba(0, 0, 0, 0.25) !important;
    border-color: #f5b700 !important;
    transform: scale(1.1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

/* Hide settings button on mobile */
@media (max-width: 768px) {
    #nav-settings-btn {
        display: none !important;
    }
}

/* 可訪問性：鍵盤導航的 focus 樣式 */
a:focus,
button:focus,
.nav-item:focus,
.hamburger:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* 移除預設的 focus outline，使用自訂樣式 */
a:focus-visible,
button:focus-visible,
.nav-item:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* 確保互動元素在鍵盤導航時有明顯的視覺指示 */
.project-info:focus-within {
    outline: 2px solid var(--accent-color);
    outline-offset: 4px;
}

/* Skip to main content link for screen readers and keyboard users */
.skip-to-main {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 999;
    padding: 1em;
    background-color: var(--accent-color);
    color: #000;
    text-decoration: none;
    font-weight: bold;
}

.skip-to-main:focus {
    left: 50%;
    transform: translateX(-50%);
    outline: 3px solid var(--text-color);
}