/* ======================
   基礎樣式與重置
   ====================== */
body {
    margin: 0;
    font-family: sans-serif;
    background: linear-gradient(to bottom right, #254441 0%, #429D9E 100%);
}

/* 通用隱藏類別 */
.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ======================
   A-Frame 場景設定
   ====================== */
a-scene {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

a-scene:not(.ar-started) {
    opacity: 0;
    pointer-events: none;
}

a-scene.ar-started {
    opacity: 1;
    pointer-events: all;
}

#ar-scene,
video {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* ======================
   歡迎頁面
   ====================== */
.welcome-screen { 
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #F7F7FC;
    z-index: 1000;
    transition: opacity 0.5s ease-out;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: auto;
     /* 讓內容可滾動 / -webkit-overflow-scrolling: touch; / iOS 慣性滾動 */ 
}

.welcome-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

/* 標題區域 */
.welcome-screen .header-group {
    width: 100%;
    height: auto;
    background-image: url('./header-bg.svg');
    background-size: 100% auto;
    background-repeat: no-repeat;
    background-position: center bottom;
    text-align: center;
    padding-top: 48px;
    padding-bottom: 128px;
}

.header-group .festival-logo {
    display: block;
    margin: auto;
}

/* 修改標題樣式 - 防止換行 */
.welcome-screen .header-group h1 {
    font-size: 36px; /* 從 48px 調整為 36px */
    font-weight: 800;
    color: white;
    line-height: 1.2;
    margin: 0;
    white-space: nowrap; /* 防止換行 */
    text-overflow: ellipsis; /* 超出時顯示省略號 */
    max-width: 90%; /* 限制最大寬度 */
    margin-left: auto;
    margin-right: auto;
}

.welcome-screen .header-group .heading-content {
    position: relative;
    margin-top: 12px;
    display: inline-block;
    width: 100%; /* 確保容器寬度 */
}

.header-group .illustration-sky {
    width: 153px;
    height: auto;
    position: absolute;
    top: 4px;
    right: -48px;
    transform: translateX(100%);
}

/* 內容區域 */
.content-group-container {
    width: calc(100% - 24px);
    height: 100%;
    display: flex;
    justify-content: center;
    padding: 0 12px;
}

.content-group {
    width: 100%;
    max-width: 1217px;
    background-color: white;
    box-shadow: 0 2px 24px 0 rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    margin-top: -64px;
    height: calc(100% + 32px);
    text-align: center;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    padding: 60px 20px 20px 20px; /* 增加內邊距 */
}

.content-group .illustration-character {
    height: 89px;
    width: auto;
    position: absolute;
    top: -52.5px;
    left: 25%;
    z-index: 2;
}

/* 修改圖片組區域 - 增加間隔 */
.content-group .image-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 24px; /* 增加元素間的間隔 */
    padding: 20px 0; /* 增加上下內邊距 */
}

.content-group .image-group p {
    font-size: 18px; /* 稍微調小字體 */
    line-height: 1.3;
    font-weight: 800;
    color: #254441;
    margin: 0; /* 移除預設 margin，使用 gap 控制間隔 */
    text-align: center;
}

/* 修改目標圖片樣式 - 移除陰影並放大 */
.target-image {
    width: 260px; /* 從 200px 放大到 260px */
    height: 260px; /* 從 200px 放大到 260px */
    border-radius: 8px;
    object-fit: contain;
    margin: 16px 0; /* 保持上下間隔 */
    /* 移除 box-shadow */
}

/* 修改按鈕區域 - 增加間隔 */
.start-button {
    margin: 24px auto 48px auto; /* 增加上方間隔 */
    width: 300px; /* 稍微調小按鈕寬度 */
}

/* ======================
   按鈕樣式
   ====================== */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 64px; /* 稍微調小按鈕高度 */
    padding: 0 24px;
    gap: 8px;
    background-color: rgb(0 178 2);
    background-image: linear-gradient(to right top, rgb(0, 178, 2) 0%, rgb(0, 178, 2) 50%, rgb(0, 122, 0) 100%);
    border-radius: 9999px;
    border: 2px solid rgb(203 245 195);
    font-size: 22px; /* 稍微調小字體 */
    font-weight: 700;
    color: rgb(255 255 255);
    text-shadow: 0 1px 0 #007a00;
    box-shadow: 0 4px 16px rgba(0, 178, 2, .3);
    cursor: pointer;
    transition: border .5s, background-position .5s, background .5s, box-shadow .5s, opacity .5s;
    background-size: 200%;
    background-position: 100% 0;
    width: 100%; /* 確保按鈕填滿容器 */
}

.button:hover {
    border-width: 2px;
    border-color: rgb(0 216 29);
    background-position: 0 100%;
    box-shadow: 0 4px 24px rgba(0, 178, 2, .6);
}

.button:active {
    box-shadow: none;
    background-image: none;
    background-color: rgb(0 122 0);
}

.button:disabled {
    background: #666;
    border-color: #888;
    cursor: not-allowed;
    box-shadow: 0 4px 15px rgba(102, 102, 102, 0.3);
    opacity: 0.7;
}

/* ======================
   載入動畫
   ====================== */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: none;
}

.spinner.show {
    display: block;
}

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

.loading-indicator {
    color: white;
    font-size: 14px;
    margin-top: 20px;
    opacity: 0.7;
    display: none;
}

/* ======================
   掃描介面
   ====================== */
.custom-scanning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: none;
    z-index: 999;
    pointer-events: none;
}

.scanning-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 280px;
    height: 356px;
    border: 3px solid #00ff88;
    border-radius: 20px;
    background: rgba(0, 255, 136, 0.1);
    animation: scanPulse 2s infinite;
}

@keyframes scanPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 255, 136, 0.7);
        transform: translate(-50%, -50%) scale(1);
    }
    70% {
        box-shadow: 0 0 0 20px rgba(0, 255, 136, 0);
        transform: translate(-50%, -50%) scale(1.02);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(0, 255, 136, 0);
        transform: translate(-50%, -50%) scale(1);
    }
}

.scanning-text {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 18px;
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    padding: 15px 25px;
    border-radius: 25px;
}

/* ======================
   狀態指示器
   ====================== */
.status-indicator {
    position: fixed;
    top: 30px;
    right: 30px;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    border-radius: 20px;
    font-size: 14px;
    z-index: 998;
}

.status-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    background: #ff4444;
    animation: blink 1s infinite;
}

.status-dot.active {
    background: #00ff88;
    animation: none;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* ======================
   音量提示
   ====================== */
.volume-notice {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 20px 30px;
    border-radius: 15px;
    text-align: center;
    z-index: 1001;
    display: none;
    max-width: 90vw;
    box-sizing: border-box;
}

.volume-notice button {
    background: #00ff88;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    margin-top: 15px;
    cursor: pointer;
    font-size: 16px;
}

/* ======================
   響應式設計
   ====================== */

/* 手機版本 */
@media (max-width: 768px) {
    .welcome-screen .header-group {
        text-align: left;
        padding: 48px 24px 160px 24px;
        display: flex;
        flex-direction: column;
    }

    .header-group .festival-logo {
        margin-left: 0;
    }

    /* 手機版標題調整 */
    .welcome-screen .header-group h1 {
        font-size: 28px; /* 手機版進一步縮小 */
        max-width: 85%; /* 手機版減少最大寬度 */
    }

    .header-group .illustration-sky {
        transform: translateX(0%);
        right: -43px;
        top: 0;
        width: 175px;
    }

    .welcome-screen .header-group .heading-content {
        width: calc(100% - 48px);
    }

    .content-group .illustration-character {
        left: 4px;
    }

    /* 手機版內容調整 */
    .content-group {
        padding: 50px 16px 16px 16px;
    }

    .content-group .image-group {
        gap: 20px;
        padding: 16px 0;
    }

    .content-group .image-group p {
        font-size: 16px;
    }

    /* 手機版圖片放大 */
    .target-image {
        width: 240px; /* 從 180px 放大到 240px */
        height: 240px; /* 從 180px 放大到 240px */
        margin: 12px 0;
    }

    .start-button {
        width: 280px;
        margin: 20px auto 40px auto;
    }

    .button {
        height: 60px;
        font-size: 20px;
    }

    .scanning-overlay {
        width: 180px;
        height: 251px;
        border-radius: 15px;
    }

    .scanning-text {
        bottom: 60px;
        font-size: 16px;
        padding: 12px 20px;
    }
}

/* 桌面版本 */
@media (min-width: 769px) {
    .scanning-overlay {
        width: 220px;
        height: 307px;
        border-radius: 20px;
    }

    .scanning-text {
        bottom: 100px;
        font-size: 18px;
    }
}

/* 極小螢幕 */
@media (max-width: 480px) {
    .welcome-screen .header-group h1 {
        font-size: 24px; /* 極小螢幕進一步縮小 */
        max-width: 80%;
    }

    .content-group {
        padding: 40px 12px 12px 12px;
    }

    .content-group .image-group {
        gap: 16px;
        padding: 12px 0;
    }

    /* 極小螢幕圖片調整 */
    .target-image {
        width: 200px; /* 從 160px 放大到 200px */
        height: 200px; /* 從 160px 放大到 200px */
        margin: 8px 0;
    }

    .start-button {
        width: 260px;
        margin: 16px auto 32px auto;
    }

    .button {
        height: 56px;
        font-size: 18px;
    }

    .scanning-overlay {
        width: 160px;
        height: 223px;
        border-radius: 12px;
    }

    .scanning-text {
        bottom: 50px;
        font-size: 14px;
        padding: 10px 15px;
    }

    .status-indicator {
        top: 20px;
        right: 20px;
        padding: 8px 15px;
        font-size: 12px;
    }

    .volume-notice {
        padding: 15px 20px;
        font-size: 16px;
    }

    .volume-notice button {
        padding: 8px 16px;
        font-size: 14px;
    }
}

/* 橫向模式 */
@media (orientation: landscape) and (max-height: 600px) {
    .welcome-screen .header-group h1 {
        font-size: 26px;
    }

    .content-group {
        padding: 30px 16px 16px 16px;
    }

    .content-group .image-group {
        gap: 12px;
        padding: 8px 0;
    }

    /* 橫向模式圖片調整 */
    .target-image {
        width: 160px; /* 從 140px 放大到 160px */
        height: 160px; /* 從 140px 放大到 160px */
        margin: 6px 0;
    }

    .start-button {
        margin: 12px auto 24px auto;
    }

    .scanning-overlay {
        width: 140px;
        height: 195px;
        border-radius: 10px;
    }

    .scanning-text {
        bottom: 30px;
        font-size: 14px;
        padding: 8px 12px;
    }

    .status-indicator {
        top: 15px;
        right: 15px;
        padding: 6px 12px;
        font-size: 11px;
    }
}

/* 高解析度螢幕 */
@media (min-width: 1200px) {
    .welcome-screen .header-group h1 {
        font-size: 42px; /* 大螢幕可以稍大一些 */
        max-width: 95%;
    }

    .content-group {
        padding: 80px 40px 40px 40px;
    }

    .content-group .image-group {
        gap: 32px;
        padding: 32px 0;
    }

    /* 高解析度螢幕圖片放大 */
    .target-image {
        width: 300px; /* 從 240px 放大到 300px */
        height: 300px; /* 從 240px 放大到 300px */
        margin: 20px 0;
    }

    .start-button {
        width: 360px;
        margin: 32px auto 60px auto;
    }

    .button {
        height: 72px;
        font-size: 24px;
    }

    .scanning-overlay {
        width: 260px;
        height: 363px;
        border-radius: 25px;
        border-width: 4px;
    }

    .scanning-text {
        bottom: 120px;
        font-size: 20px;
        padding: 18px 30px;
    }
}

/* 平板裝置 */
@media (min-width: 768px) and (max-width: 1024px) {
    .welcome-screen .header-group h1 {
        font-size: 32px;
        max-width: 90%;
    }

    .content-group {
        padding: 60px 24px 24px 24px;
    }

    .content-group .image-group {
        gap: 24px;
        padding: 20px 0;
    }

    /* 平板裝置圖片調整 */
    .target-image {
        width: 260px; /* 從 200px 放大到 260px */
        height: 260px; /* 從 200px 放大到 260px */
        margin: 16px 0;
    }

    .start-button {
        width: 320px;
        margin: 24px auto 48px auto;
    }

    .scanning-overlay {
        width: 200px;
        height: 279px;
        border-radius: 18px;
    }

    .scanning-text {
        bottom: 80px;
        font-size: 17px;
        padding: 14px 24px;
    }
}

/* iOS Safari 特殊處理 */
@supports (-webkit-touch-callout: none) {
    .scanning-overlay {
        transform: translate(-50%, -50%) scale(0.95);
    }
}
