/* 3D 工作室畫廊（portfolio-3d.js）。顏色一律走 --ex-* token，深淺主題共用。
   預設只顯示啟動按鈕；按下後在頁面中展開（手機自動滿版）。 */

/* ---------- 啟動按鈕 ---------- */
.pf3d-launch-row {
    display: flex;
    justify-content: center;
    margin: 0 0 32px;
}
.pf3d-launch-row[hidden] {
    display: none;
}
.pf3d-launch {
    display: flex;
    align-items: center;
    gap: 16px;
    width: min(100%, 560px);
    min-height: 72px;
    padding: 12px 20px 12px 12px;
    font: inherit;
    text-align: left;
    color: var(--ex-text);
    background: var(--ex-surface);
    border: 1px solid var(--ex-border-strong);
    border-radius: 1px;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.pf3d-launch:hover {
    border-color: var(--ex-ink);
    transform: translateY(-1px);
    box-shadow: var(--ex-shadow-1);
}
.pf3d-launch-icon {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    font-size: 26px;
    color: var(--ex-surface);
    background: var(--ex-ink);
    border-radius: 1px;
}
.pf3d-launch-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.pf3d-launch-text strong {
    font-size: 1.05rem;
    color: var(--ex-ink);
}
.pf3d-launch-text small {
    font-size: 0.85rem;
    color: var(--ex-text-2);
}
.pf3d-launch-arrow {
    color: var(--ex-link);
    transition: transform 0.2s ease;
}
.pf3d-launch:hover .pf3d-launch-arrow {
    transform: translate(2px, -2px);
}

/* ---------- 展廳畫面 ---------- */
.pf3d-stage {
    position: relative;
    height: min(78vh, 760px);
    min-height: 460px;
    margin: 0 0 40px;
    overflow: hidden;
    background: var(--ex-surface);
    border: 1px solid var(--ex-border);
    outline-offset: 4px;
}
.pf3d-stage.is-expanded,
.pf3d-stage:fullscreen {
    position: fixed;
    inset: 0;
    z-index: 10000;   /* 低於案例詳情（10001） */
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    border: 0;
}
html.pf3d-locked,
html.pf3d-locked body {
    overflow: hidden;
}
html.pf3d-locked .oceanai-fab-wrap {
    display: none !important;
}
.pf3d-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: pan-y;
    opacity: 0;
    transition: opacity 0.8s ease;
}
.pf3d-stage.is-expanded .pf3d-canvas {
    touch-action: none;
}
.pf3d-stage[data-state="ready"] .pf3d-canvas {
    opacity: 1;
}

/* 載入中／錯誤的封面 */
.pf3d-cover {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
    background: var(--ex-bg);
    transition: opacity 0.6s ease, visibility 0.6s;
}
.pf3d-stage[data-state="ready"] .pf3d-cover {
    opacity: 0;
    visibility: hidden;
}
.pf3d-status {
    margin: 0;
    color: var(--ex-text);
    font-weight: 600;
}
.pf3d-loader {
    width: 28px;
    height: 28px;
    border: 2px solid var(--ex-border-strong);
    border-top-color: var(--ex-link);
    animation: pf3d-spin 0.9s linear infinite;
}
.pf3d-stage[data-state="error"] .pf3d-loader {
    display: none;
}
@keyframes pf3d-spin {
    to { transform: rotate(360deg); }
}

/* ---------- HUD ---------- */
.pf3d-hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease 0.6s, visibility 0s 0.6s;
}
.pf3d-stage[data-state="ready"] .pf3d-hud {
    opacity: 1;
    visibility: visible;
}
.pf3d-hud > * {
    pointer-events: auto;
}
.pf3d-top,
.pf3d-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.pf3d-where {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--ex-text);
    background: var(--ex-surface);
    border: 1px solid var(--ex-border);
    padding: 8px 12px;
}
.pf3d-caption {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--ex-surface);
    border: 1px solid var(--ex-border);
    padding: 10px 10px 10px 18px;
}
.pf3d-caption-text {
    flex: 1;
    min-width: 0;
}
.pf3d-caption-text span {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--ex-link);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.pf3d-caption-text strong {
    display: block;
    font-size: 1.05rem;
    color: var(--ex-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pf3d-btn {
    display: inline-flex;
    flex-shrink: 0;
    white-space: nowrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    min-width: 44px;
    padding: 0 18px;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ex-text);
    background: var(--ex-surface);
    border: 1px solid var(--ex-border-strong);
    border-radius: 1px;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.pf3d-btn:hover {
    border-color: var(--ex-ink);
    color: var(--ex-ink);
}
.pf3d-btn-primary {
    background: var(--ex-ink);
    border-color: var(--ex-ink);
    color: var(--ex-surface);
}
.pf3d-btn-primary:hover {
    background: var(--ex-text);
    border-color: var(--ex-text);
    color: var(--ex-surface);
}
.pf3d-btn .material-icons {
    font-size: 1.25rem;
}
.pf3d-icon {
    padding: 0;
}
.pf3d-btn[aria-expanded="true"] {
    background: var(--ex-ink);
    border-color: var(--ex-ink);
    color: var(--ex-surface);
}

/* 前往展廳：純圖示，雙層直角框 */
.pf3d-go {
    position: relative;
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin: 6px 6px 6px auto;
    padding: 0;
    color: var(--ex-surface);
    background: var(--ex-ink);
    border: 0;
    border-radius: 1px;
    outline: 1px solid var(--ex-border-strong);
    outline-offset: 5px;
    cursor: pointer;
    transition: outline-offset 0.3s ease, outline-color 0.3s ease, background 0.2s ease;
}
.pf3d-go::before {
    content: "";
    position: absolute;
    inset: 6px;
    border: 1px solid currentColor;
    opacity: 0.18;
    pointer-events: none;
}
.pf3d-go .material-icons {
    font-size: 28px;
    transition: transform 0.3s ease;
}
.pf3d-go:hover {
    outline-color: var(--ex-ink);
    outline-offset: 8px;
}
.pf3d-go:hover .material-icons {
    transform: translateX(3px);
}
.pf3d-go:focus-visible {
    outline: 2px solid var(--ex-link);
    outline-offset: 5px;
}
@media (prefers-reduced-motion: no-preference) {
    .pf3d-go {
        animation: pf3d-breathe 2.8s ease-in-out infinite;
    }
    .pf3d-go:hover {
        animation: none;
    }
}
@keyframes pf3d-breathe {
    50% { outline-offset: 9px; outline-color: transparent; }
}

/* ---------- 下拉選單 ---------- */
.pf3d-menu-wrap {
    position: relative;
    flex-shrink: 0;
}
.pf3d-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 2;
    min-width: 216px;
    display: flex;
    flex-direction: column;
    padding: 6px;
    background: var(--ex-surface);
    border: 1px solid var(--ex-border-strong);
    box-shadow: var(--ex-shadow-2);
}
.pf3d-menu[hidden] {
    display: none;
}
.pf3d-menu button {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 0 14px 0 10px;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    text-align: left;
    color: var(--ex-text);
    background: transparent;
    border: 0;
    border-radius: 1px;
    cursor: pointer;
}
.pf3d-menu button .material-icons {
    font-size: 1.2rem;
    color: var(--ex-text-2);
}
.pf3d-menu button:hover,
.pf3d-menu button:focus-visible {
    background: var(--ex-bg);
    color: var(--ex-ink);
    outline: none;
}
.pf3d-menu [data-pf3d-action="exit"] {
    margin-top: 4px;
    border-top: 1px solid var(--ex-border);
    border-radius: 0;
}
.pf3d-stage[data-zone="hall"] .pf3d-menu [data-pf3d-action="hall"],
.pf3d-stage[data-zone="studio"] .pf3d-menu [data-pf3d-action="studio"],
.pf3d-stage.is-expanded .pf3d-menu [data-pf3d-action="expand"],
.pf3d-stage:not(.is-expanded) .pf3d-menu [data-pf3d-action="collapse"] {
    display: none;
}

/* 底部導航：作品目錄（橫向縮圖條） */
.pf3d-dock {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.pf3d-catalog {
    background: var(--ex-surface);
    border: 1px solid var(--ex-border);
}
.pf3d-catalog[hidden] {
    display: none;
}
.pf3d-catalog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 4px 0 14px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--ex-text-2);
}
.pf3d-btn-quiet {
    border-color: transparent;
    background: transparent;
}
.pf3d-strip {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding: 6px 14px 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--ex-border-strong) transparent;
}
.pf3d-strip-group {
    display: flex;
    align-items: stretch;
    gap: 6px;
    flex-shrink: 0;
}
.pf3d-strip-cat {
    writing-mode: vertical-rl;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--ex-link);
    padding: 4px 2px;
}
.pf3d-strip-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 128px;
    padding: 4px;
    font: inherit;
    text-align: left;
    color: var(--ex-text-2);
    background: transparent;
    border: 0;
    border-radius: 1px;
    cursor: pointer;
    scroll-snap-align: center;
    transition: background 0.2s ease, color 0.2s ease;
}
.pf3d-strip-item img {
    display: block;
    width: 120px;
    height: 90px;
    object-fit: cover;
    background: var(--ex-border);
}
.pf3d-strip-no {
    position: absolute;
    top: 8px;
    left: 8px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 1px 5px;
    color: var(--ex-surface);
    background: var(--ex-ink);
}
.pf3d-strip-title {
    font-size: 0.8rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.pf3d-strip-item:hover {
    color: var(--ex-ink);
    background: var(--ex-bg);
}
.pf3d-strip-item.is-current {
    background: var(--ex-ink);
    color: var(--ex-surface);
    font-weight: 700;
}
.pf3d-strip-item.is-current .pf3d-strip-no {
    background: var(--ex-link);
    color: var(--ex-bg);
}

/* 亮色模式：design-2025 的 body.day-mode span 以 !important 統一改色，
   展廳內的 span 改回各自的顏色，維持 4.5:1 以上的對比 */
body.day-mode .pf3d-stage span,
body.day-mode .pf3d-launch span {
    color: inherit !important;
}
body.day-mode .pf3d-where {
    color: var(--ex-text) !important;
}
body.day-mode .pf3d-caption-text span,
body.day-mode .pf3d-strip-cat,
body.day-mode .pf3d-launch .pf3d-launch-arrow {
    color: var(--ex-link) !important;
}
body.day-mode .pf3d-strip-no,
body.day-mode .pf3d-launch .pf3d-launch-icon {
    color: var(--ex-surface) !important;
}
body.day-mode .pf3d-strip-item.is-current .pf3d-strip-no {
    color: var(--ex-bg) !important;
}
body.day-mode .pf3d-menu button .material-icons {
    color: var(--ex-text-2) !important;
}

/* 依所在區域切換 HUD */
.pf3d-stage[data-zone="studio"] [data-zone-only="hall"],
.pf3d-stage[data-zone="hall"] [data-zone-only="studio"] {
    display: none;
}

.pf3d-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (max-width: 760px) {
    .pf3d-launch {
        padding-right: 14px;
    }
    .pf3d-launch-text small {
        font-size: 0.8rem;
    }
    .pf3d-stage {
        height: 74svh;
        min-height: 480px;
        margin: 0 -16px 32px;
        border-left: 0;
        border-right: 0;
    }
    .pf3d-hud {
        padding: 12px;
        padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }
    .pf3d-bottom {
        flex-wrap: wrap;
    }
    .pf3d-caption {
        order: -1;
        flex-basis: 100%;
        padding: 8px 8px 8px 14px;
    }
    .pf3d-bottom .pf3d-nav {
        flex: 1;
    }
    .pf3d-go {
        width: 60px;
        height: 60px;
    }
    .pf3d-strip-item {
        width: 104px;
    }
    .pf3d-strip-item img {
        width: 96px;
        height: 72px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pf3d-canvas,
    .pf3d-cover,
    .pf3d-hud {
        transition: none;
    }
    .pf3d-loader {
        animation: none;
    }
}
