/* Mobile Layout Fixes - 手機模式修正 */

/* 确保所有元素不超出屏幕 */
* {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

html {
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* 修复导航栏在移动端的问题 */
@media (max-width: 768px) {
    nav {
        padding: 1rem 1rem !important;
        width: 100%;
        box-sizing: border-box;
    }

    /* 修正：首頁頂端 nav 使用 mix-blend-mode:difference 會讓選單黑底被混色吃掉。
       選單打開時暫時關閉混色，確保背景真的變黑。 */
    body.menu-open nav {
        mix-blend-mode: normal !important;
    }

    nav.scrolled {
        padding: 0.8rem 1rem !important;
        margin: 0.5rem;
        width: calc(100% - 1rem);
        box-sizing: border-box;
    }

    .logo {
        font-size: 0.85rem !important;
        letter-spacing: 0.1em;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 60%;
    }

    /* Hamburger 菜单样式 */
    .hamburger {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: 28px;
        height: 20px;
        cursor: pointer;
        position: relative;
        z-index: 1001;
        flex-shrink: 0;
    }

    .hamburger .line {
        width: 100%;
        height: 3px;
        background: var(--gold-500);
        border-radius: 2px;
        transition: all 0.3s ease;
        display: block;
    }

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

    .hamburger.active .line:nth-child(2) {
        opacity: 0;
    }

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

    /* 手機導航選單 – iPhone 修正版 */
    .nav-links {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        background: #030303;         /* 實色：無論 glassi-fy 在不在都能遞羋 */
        will-change: transform;
        transform: translateZ(0);    /* 強制独立 GPU 層 */
        -webkit-transform: translateZ(0);
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2rem;
        z-index: 99999;              /* 大於 glassi-fy 的任何 z-index */
        padding: 2rem;
        box-sizing: border-box;
        isolation: isolate;
    }

    .nav-links.active {
        display: flex;
    }

    .nav-links li {
        opacity: 0;
        transform: translateY(20px);
        animation: fadeInUp 0.5s forwards;
    }

    .nav-links li:nth-child(1) {
        animation-delay: 0.1s;
    }

    .nav-links li:nth-child(2) {
        animation-delay: 0.2s;
    }

    .nav-links li:nth-child(3) {
        animation-delay: 0.3s;
    }

    .nav-links li:nth-child(4) {
        animation-delay: 0.4s;
    }

    .nav-links li:nth-child(5) {
        animation-delay: 0.5s;
    }

    .nav-links li:nth-child(6) {
        animation-delay: 0.6s;
    }

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

    .nav-links a {
        font-size: 1.2rem;
        padding: 1rem;
    }

    /* Hero 区块文字防止溢出 */
    .title-line {
        font-size: clamp(2rem, 10vw, 3rem) !important;
        word-break: keep-all;
        hyphens: auto;
    }

    .subtitle {
        font-size: clamp(0.9rem, 3vw, 1.2rem) !important;
        padding: 0 1rem;
        text-align: center;
    }

    .hero-info {
        width: 100%;
        padding: 1rem;
        box-sizing: border-box;
    }

    .info-item {
        font-size: clamp(0.8rem, 2.5vw, 1rem);
        padding: 0.5rem;
    }

    /* 每個 container 占滿一個螢幕高度並垂直置中 */
    .container {
        width: 100%;
        max-width: 100vw;
        /* svh = small viewport height，排除 iOS 位址列影響 */
        min-height: 100svh;
        min-height: 100vh;
        /* fallback */
        padding: 60px 5% !important;
        box-sizing: border-box;
        overflow-x: hidden;
        /* 讓內容垂直居中 */
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .cast-name-large {
        font-size: clamp(1.2rem, 6vw, 2.5rem) !important;
    }

    .expanded-info {
        gap: 0.5rem;
    }

    .cast-role-large {
        font-size: clamp(1rem, 2.5vw, 1rem) !important;
    }

    .cast-description {
        font-size: clamp(1rem, 2.5vw, 1rem);
    }

    /* 互動遊戲區：內容可能超出螢幕，允許縱向捲動 */
    .game-section {
        overflow-y: auto;
        align-items: stretch;
    }

    /* 周邊商品區：容許 merch-grid 內部水平滚動，不裁切 */
    #merch.container {
        overflow-x: clip;        /* clip 裁切自身 overflow，不影響子元素的 scroll 容器 */
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    #merch .section-title {
        padding: 0 5%;
    }

    /* hero header 也占滿螢幕 */
    header#hero {
        min-height: 100svh;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Section titles */
    .section-title h2 {
        font-size: clamp(1.8rem, 6vw, 2.5rem) !important;
        word-break: keep-all;
    }

    .section-subtitle {
        font-size: clamp(0.7rem, 2vw, 0.9rem);
    }

    /* 修复文字内容溢出 */
    p,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }

    /* Stage container */
    .stage-container {
        width: 100%;
        box-sizing: border-box;
    }

    .act-slide {
        padding: 1.5rem;
        box-sizing: border-box;
    }

    .act-slide h3 {
        font-size: clamp(1.5rem, 5vw, 2.5rem) !important;
    }

    .act-slide p {
        font-size: clamp(0.85rem, 2.5vw, 1rem);
        line-height: 1.6;
    }

    /* 修复图片和媒体元素 */
    img,
    video,
    iframe {
        max-width: 100%;
        height: auto;
    }

    /* 修复按钮 */
    .btn-main {
        padding: 12px 24px;
        font-size: 0.9rem;
        white-space: nowrap;
    }

    /* Footer */
    footer {
        padding: 40px 5% !important;
        width: 100%;
        box-sizing: border-box;
    }

    .footer-top {
        flex-direction: column;
        gap: 2rem;
    }

    .ticket-info,
    .contact-info {
        width: 100%;
        box-sizing: border-box;
    }
}

/* 平板横向 */
@media (min-width: 481px) and (max-width: 768px) {
    .title-line {
        font-size: clamp(2.5rem, 8vw, 3.5rem) !important;
    }

    .container {
        padding: 10px 8% !important;
        margin-top: 4rem;
    }

    nav {
        padding: 1rem 2rem !important;
    }

    .hamburger {
        display: flex;
    }

    .nav-links {
        display: none;
    }
}

/* 小屏设备通用修复 */
@media (max-width: 968px) {

    /* 确保 canvas 不溢出 */
    #canvas-container {
        width: 100%;
        max-width: 100vw;
        overflow: hidden;
    }

    /* 确保所有内容区块不溢出 */
    section {
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
        overflow-x: hidden;
    }
}

/* Team Section Mobile Popup & Interactions */
@media (max-width: 768px) {

    /* 1. team-group-photo ONLY show text details */
    .team-group-photo {
        height: auto !important;
        background: transparent !important;
    }

    .team-group-photo .photo-placeholder {
        display: none !important;
        /* Hide center image placeholder */
    }

    .team-group-photo .photo-overlay {
        position: relative !important;
        opacity: 1 !important;
        background: transparent !important;
        padding: 0 !important;
        pointer-events: auto !important;
    }

    .team-group-photo .overlay-content {
        transform: none !important;
        padding-top: 0 !important;
        max-width: 100% !important;
    }

    .team-group-slide .photo-hint {
        display: none !important;
    }

    .team-group-slide .team-group-photo-wrapper {
        gap: 0 !important;
    }

    /* 2. other members initially show photo, role, name */
    .team-slide:not(.team-group-slide) {
        flex-direction: column !important;
        justify-content: flex-start !important;
        gap: 1rem !important;
        height: auto !important;
        min-height: auto !important;
        padding: 1rem 0 !important;
    }

    .team-slide:not(.team-group-slide) .team-photo {
        width: 80% !important;
        flex: 0 0 auto !important;
        max-width: 280px;
        height: 350px !important;
        margin: 0 auto;
        cursor: pointer;
    }

    .team-slide:not(.team-group-slide) .team-info {
        align-items: center !important;
        text-align: center !important;
        gap: 0.8rem !important;
    }

    .team-slide:not(.team-group-slide) .role-badge {
        align-self: center !important;
    }

    /* 3. Initial state: hide bio */
    .team-slide:not(.team-group-slide) .member-bio {
        display: none !important;
        /* Forces hide initially */
    }

    /* 4. Click hint on photo */
    .team-slide:not(.team-group-slide) .team-photo::after {
        content: '點擊查看介紹';
        position: absolute;
        bottom: 15px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.7);
        color: #fff;
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 0.85rem;
        pointer-events: none;
        opacity: 0.9;
        font-family: 'Noto Sans TC', sans-serif;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    }

    /* 5. "Pop-up" active state for bio */
    .team-slide:not(.team-group-slide).show-bio .member-bio {
        display: flex !important;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 85vw;
        max-height: 75vh;
        overflow-y: auto;
        background: #1a1a1a;
        border: 1px solid rgba(212, 175, 55, 0.4);
        padding: 2.5rem 1.5rem 1.5rem;
        border-radius: 12px;
        z-index: 10000;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
        text-align: left !important;
        flex-direction: column;
        gap: 1rem;
        animation: bioPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
        overscroll-behavior: contain;
    }

    /* Close button pseudo-element */
    .team-slide:not(.team-group-slide).show-bio .member-bio::before {
        content: '✕';
        position: absolute;
        top: 10px;
        right: 15px;
        font-size: 1.2rem;
        color: #B0B0B0;
        font-family: sans-serif;
        cursor: pointer;
        padding: 5px;
        z-index: 10001;
    }

    @keyframes bioPop {
        0% {
            opacity: 0;
            transform: translate(-50%, -45%) scale(0.95);
        }

        100% {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
        }
    }

    /* Fixed overlay backdrop */
    .bio-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 9999;
    }

    .bio-backdrop.show {
        display: block;
    }
}