/* 星空背景設定 */
body { 
    margin: 0; 
    padding: 0; 
    font-family: '微軟正黑體', sans-serif; 
    text-align: center; 
    min-height: 100vh; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    overflow-x: hidden;
    color: #e0d4ff;
    background-color: #0b0d17;
    background-image: url('images/001.webp');
    background-size: cover; 
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

.container { width: 95%; max-width: 1050px; padding: 30px; position: relative; z-index: 1; }
.main-title { color: #d4b5ff; text-shadow: 0 0 15px rgba(212, 181, 255, 0.8), 0 0 30px rgba(100, 50, 200, 0.6); font-size: 2.8em; margin-bottom: 10px;}
.subtitle { font-size: 1.2em; color: #bca0ff; font-weight: bold; text-shadow: 0 2px 5px rgba(0,0,0,0.8); }
.instruction-text { font-size: 1.1em; color: #bca0ff; font-weight: bold; margin-bottom: 10px; text-shadow: 0 2px 5px rgba(0,0,0,0.8); }
.topic-display { color: #ffffff; font-weight: bold; font-size: 1.3em; background: rgba(50, 20, 100, 0.6); display: inline-block; padding: 5px 20px; border-radius: 20px; box-shadow: 0 0 15px rgba(160, 132, 255, 0.3); border: 1px solid rgba(160, 132, 255, 0.5); margin-bottom: 10px; backdrop-filter: blur(5px); }

.topic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 25px; max-width: 500px; margin-left: auto; margin-right: auto; }
.topic-grid button { background: rgba(15, 10, 30, 0.7); color: #e0d4ff; border: 1px solid rgba(160, 132, 255, 0.5); padding: 15px 10px; border-radius: 15px; cursor: pointer; font-size: 18px; font-weight: bold; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8); display: flex; flex-direction: column; align-items: center; justify-content: center; backdrop-filter: blur(8px); }
.topic-grid button .icon { font-size: 26px; margin-bottom: 5px; }
.topic-grid button small { font-size: 13px; color: #a084ff; margin-top: 2px; font-weight: normal; }
.topic-grid button:hover { background: linear-gradient(135deg, rgba(123, 44, 191, 0.8), rgba(74, 35, 90, 0.8)); color: #fff; transform: translateY(-5px); box-shadow: 0 8px 25px rgba(160, 132, 255, 0.6); border-color: #d4b5ff; }
.topic-grid button:hover small { color: #f3e5f5; }

.custom-topic { margin-top: 30px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.custom-topic input { padding: 15px 20px; border-radius: 30px; border: 1px solid rgba(160, 132, 255, 0.5); background: rgba(10, 5, 25, 0.8); color: white; width: 300px; font-size: 16px; outline: none; transition: all 0.3s; box-shadow: inset 0 0 10px rgba(0,0,0,0.8); backdrop-filter: blur(5px); }
.custom-topic input:focus { border-color: #d4b5ff; box-shadow: 0 0 15px rgba(160, 132, 255, 0.5); }
.custom-topic input::placeholder { color: #7a6a99; }
.custom-topic button { padding: 12px 30px; border-radius: 30px; border: none; background: linear-gradient(135deg, #7b2cbf 0%, #4a235a 100%); color: white; cursor: pointer; font-weight: bold; font-size: 16px; transition: 0.3s; box-shadow: 0 4px 15px rgba(123, 44, 191, 0.6); border: 1px solid #9b59b6; }
.custom-topic button:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(212, 181, 255, 0.6); }

.tarot-mat {
    background: rgba(20, 10, 40, 0.25); 
    border: 1px solid rgba(160, 132, 255, 0.3);
    border-radius: 20px;
    padding: 40px 20px 60px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.4), inset 0 0 30px rgba(0,0,0,0.3);
    margin-top: 20px;
    backdrop-filter: blur(8px);
}

.deck-spread { 
    position: relative; 
    width: 100%; 
    height: 360px; 
    margin: 0px auto 60px; 
    display: flex; 
    justify-content: center; 
    align-items: flex-end; 
    transition: opacity 0.5s ease; 
    transform-style: preserve-3d;
    perspective: 1200px; 
}

/* 絲滑感應區 */
.spread-card { 
    position: absolute; 
    width: 110px;   
    height: 190px;  
    cursor: pointer; 
    transform-origin: center 220%; 
    bottom: 150px;  
    transform: rotate(var(--rot)) translate3d(0, 0, 0); 
    background: transparent; 
    transform-style: preserve-3d; 
}

/* 視覺卡片 */
.spread-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: url('images/card-back.webp') no-repeat center/cover; 
    border-radius: 10px; 
    box-shadow: -2px 0 8px rgba(0,0,0,0.7); 
    border: 1px solid rgba(160, 132, 255, 0.4); 
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), filter 0.4s ease; 
    pointer-events: none; 
    transform: translateZ(1px); 
}

.tarot-container { 
    display: flex; 
    justify-content: space-around; 
    margin-top: 50px; 
    gap: 20px; 
    flex-wrap: wrap;
}
.tarot-card { perspective: 1000px; width: 140px; height: 245px; margin-bottom: 20px; }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275); transform-style: preserve-3d; }
.tarot-card.flipped .card-inner { transform: rotateY(180deg); }

.empty-slot { opacity: 0.7; }
.empty-slot .card-inner { border: 2px dashed #a084ff; border-radius: 12px; background: rgba(50, 20, 100, 0.3); backdrop-filter: blur(3px); }
.empty-slot .card-front, .empty-slot .card-back { display: none; }

.card-front, .card-back { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; border-radius: 12px; border: 2px solid rgba(160, 132, 255, 0.6); overflow: hidden; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8); }
.card-back { background-color: #0b0d17; }
.card-back img { width: 100%; height: 100%; object-fit: cover; }
.tarot-card:hover .card-back { box-shadow: 0 0 25px rgba(160, 132, 255, 0.8); border-color: #d4b5ff; }

.card-front { background-color: #fff; color: #333; transform: rotateY(180deg); display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; }
.card-front img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease; }
.card-front img.reversed-img { transform: rotate(180deg); }

.card-title { font-weight: bold; margin-top: 15px; color: #d4b5ff; text-shadow: 0 0 5px rgba(0,0,0,0.9); font-size: 1.1em; }

.card-name-label { 
    position: absolute; 
    bottom: 28px; 
    left: 50%;
    transform: translateX(-50%); 
    background: linear-gradient(135deg, rgba(89, 36, 150, 0.9), rgba(30, 11, 60, 0.95)); 
    color: #ffffff; 
    padding: 6px 18px; 
    border-radius: 25px; 
    font-size: 15px; 
    font-weight: bold; 
    letter-spacing: 3px; 
    border: 1px solid rgba(212, 181, 255, 0.8); 
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8), 0 0 12px rgba(160, 132, 255, 0.6); 
    backdrop-filter: blur(8px); 
    white-space: nowrap;
    z-index: 10; 
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

.hidden { display: none !important; }

#result-box { margin-top: 40px; padding: 30px; background: rgba(10, 5, 25, 0.85); border-radius: 15px; border: 1px solid rgba(160, 132, 255, 0.5); white-space: pre-wrap; text-align: left; line-height: 1.8; font-size: 16px; color: #e0d4ff; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8); backdrop-filter: blur(15px); }
.result-title { color: #d4b5ff; font-size: 1.5em; text-align: center; margin-bottom: 20px; text-shadow: 0 0 15px rgba(212, 181, 255, 0.6); }
.reading-time { text-align: center; color: #a084ff; font-size: 0.9em; margin-bottom: 15px; border-bottom: 1px dashed rgba(160, 132, 255, 0.4); padding-bottom: 10px; }

.action-buttons { display: flex; justify-content: center; gap: 20px; margin-top: 25px; flex-wrap: wrap; }
.action-btn { padding: 12px 30px; border-radius: 30px; border: none; cursor: pointer; font-weight: bold; font-size: 16px; transition: 0.3s; }
#restart-btn { background: linear-gradient(135deg, #7b2cbf 0%, #4a235a 100%); color: white; box-shadow: 0 4px 15px rgba(123, 44, 191, 0.5); border: 1px solid #9b59b6; }
#restart-btn:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(212, 181, 255, 0.6); }
.save-btn-style { background: rgba(10, 5, 25, 0.5); border: 2px solid #a084ff; color: #d4b5ff; backdrop-filter: blur(5px); }
.save-btn-style:hover { background: rgba(160, 132, 255, 0.3); transform: scale(1.05); color: #fff; border-color: #fff;}

/* 頂部按鈕共用樣式 */
#back-games-btn, #lang-toggle-btn, #view-fav-btn { position: absolute; top: 20px; background: rgba(20, 15, 40, 0.8); border: 1px solid #a084ff; color: #d4b5ff; padding: 10px 20px; border-radius: 20px; cursor: pointer; z-index: 100; transition: 0.3s; font-weight: bold; backdrop-filter: blur(10px); box-shadow: 0 0 10px rgba(0,0,0,0.8); }
#back-games-btn:hover, #lang-toggle-btn:hover, #view-fav-btn:hover { background: #7b2cbf; color: white; box-shadow: 0 0 20px rgba(160, 132, 255, 0.8); }

/* 位置設定 */
#back-games-btn { left: 20px; }
#lang-toggle-btn { left: 180px; }
#view-fav-btn { right: 20px; }

#back-to-menu-btn {
    display: inline-block;
    margin-bottom: 15px;
    background: rgba(20, 10, 40, 0.6);
    border: 1px dashed rgba(160, 132, 255, 0.6);
    color: #d4b5ff;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: bold;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

#back-to-menu-btn:hover {
    background: rgba(123, 44, 191, 0.6);
    color: #fff;
    border: 1px solid #d4b5ff;
    transform: translateY(-2px);
}

#favorites-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.85); z-index: 1000; display: flex; justify-content: center; align-items: center; backdrop-filter: blur(8px); }
.modal-content { background: rgba(19, 12, 37, 0.95); border: 1px solid #7b2cbf; width: 90%; max-width: 700px; max-height: 80vh; border-radius: 15px; padding: 30px; overflow-y: auto; position: relative; box-shadow: 0 0 40px rgba(123, 44, 191, 0.6); text-align: left; }
.close-btn { position: absolute; top: 15px; right: 20px; font-size: 28px; color: #a084ff; cursor: pointer; transition: 0.3s; }
.close-btn:hover { color: #fff; }

.fav-item { background: rgba(255, 255, 255, 0.05); border: 1px solid rgba(160, 132, 255, 0.3); border-radius: 10px; padding: 20px; margin-bottom: 20px; }
.fav-item h4 { margin-top: 0; color: #d4b5ff; border-bottom: 1px solid rgba(160, 132, 255, 0.3); padding-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.fav-time { font-size: 0.8em; color: #a084ff; font-weight: normal; }
.fav-cards { font-size: 0.9em; color: #d4b5ff; background: rgba(0,0,0,0.5); padding: 10px; border-radius: 8px; border: 1px solid rgba(160,132,255,0.2); }
.fav-reading { color: #e0d4ff; line-height: 1.6; font-size: 0.95em; }
/* AI 解讀的排版（Markdown 轉出來的標題、清單、分隔線） */
.reading-heading { margin: 14px 0 6px; color: #f5d68a; font-size: 1.05em; font-weight: 700; letter-spacing: 0.5px; }
.reading-p { margin: 0 0 6px; }
.reading-list { margin: 4px 0 8px; padding-left: 1.3em; }
.reading-list li { margin-bottom: 6px; }
.reading-hr { border: none; border-top: 1px dashed rgba(160, 132, 255, 0.4); margin: 12px 0; }
.reading-gap { height: 6px; }
#ai-reading-result strong, .fav-reading strong { color: #f5d68a; }
.delete-btn { background: transparent; border: 1px solid #e74c3c; color: #e74c3c; padding: 5px 15px; border-radius: 15px; cursor: pointer; margin-top: 10px; transition: 0.3s; }
.delete-btn:hover { background: #e74c3c; color: white; }

/* =========================================
   📱 手機版響應式設計 (Media Query)
   ========================================= */
@media screen and (max-width: 768px) {
    #back-games-btn, #lang-toggle-btn, #view-fav-btn {
        position: fixed !important;
        top: 10px !important;
        padding: 5px 8px !important;
        font-size: 11px !important;
        border-radius: 14px !important;
        z-index: 1000 !important;
    }
    #back-games-btn { left: 8px !important; right: auto !important; }
    #lang-toggle-btn { left: 106px !important; right: auto !important; }
    #view-fav-btn { right: 8px !important; left: auto !important; }

    .container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 50px 10px 30px 10px !important;
        box-sizing: border-box !important;
    }

    .main-title { font-size: 1.6rem !important; margin-top: 5px !important; margin-bottom: 6px !important; }
    .subtitle { font-size: 0.95rem !important; }
    .topic-display { font-size: 1rem !important; padding: 4px 14px !important; margin-bottom: 6px !important; }
    .instruction-text { font-size: 0.88rem !important; margin-bottom: 6px !important; }

    .topic-grid { gap: 10px !important; }
    .topic-grid button { padding: 10px 5px !important; font-size: 15px !important; }
    .custom-topic input { width: 220px !important; font-size: 14px !important; }
    .custom-topic button { padding: 10px 20px !important; font-size: 14px !important; }

    .tarot-mat {
        padding: 15px 6px 25px 6px !important;
        border-radius: 16px !important;
        margin-top: 10px !important;
    }

    .deck-spread {
        height: 170px !important;
        margin: 5px auto 25px !important;
        position: relative !important;
        z-index: 50 !important;
        perspective: 800px !important;
    }

    .spread-card {
        width: 52px !important;
        height: 90px !important;
        bottom: 55px !important;
        transform-origin: center 185% !important;
        z-index: 1 !important;
    }

    .tarot-container {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 6px !important;
        margin-top: 10px !important;
        width: 100% !important;
        position: relative !important;
        z-index: 10 !important;
    }

    .tarot-card {
        width: 86px !important;
        height: 148px !important;
        min-width: 0 !important;
        flex-shrink: 1 !important;
        margin-bottom: 0 !important;
    }

    .card-title {
        font-size: 0.78rem !important;
        margin-top: 6px !important;
        white-space: nowrap !important;
    }

    .card-name-label {
        font-size: 10px !important;
        padding: 2px 6px !important;
        bottom: 8px !important;
        letter-spacing: 0px !important;
    }

    #result-box {
        padding: 16px 12px !important;
        font-size: 13px !important;
        margin-top: 20px !important;
    }

    .action-buttons { gap: 10px !important; }
    .action-btn { padding: 8px 18px !important; font-size: 13px !important; }
}

@media screen and (max-width: 330px) {
    #back-games-btn { font-size: 10px !important; padding: 4px 6px !important; }
    #lang-toggle-btn { left: 96px !important; font-size: 10px !important; padding: 4px 6px !important; }
    #view-fav-btn { font-size: 10px !important; padding: 4px 6px !important; }
    .tarot-card { width: 80px !important; height: 138px !important; }
}

/* =========================================
   ✨ 最終修復：滑順展開、精準點擊與 X 光透視切換
   ========================================= */

/* 1. 確保實體卡牌動畫平滑與滑鼠事件正常運作 */
.spread-card {
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), opacity 0.5s ease !important;
    pointer-events: auto !important; 
}

/* 防止手機端與模擬器滑動時被瀏覽器原生手勢攔截 */
.deck-spread {
    touch-action: none !important; 
}

/* 2. 徹底關閉 CSS 原生 hover，避免跟 JS 透視邏輯衝突 (強制固定在原處) */
.spread-card:hover {
    transform: rotate(var(--rot)) translate3d(0, 0, 0) !important;
    z-index: auto !important;
}
.spread-card:hover::before {
    transform: translateZ(1px) !important;
    filter: none !important;
    border: 1px solid rgba(160, 132, 255, 0.4) !important;
    box-shadow: -2px 0 8px rgba(0,0,0,0.7) !important;
}

/* 3. 完全由 JS 的 .hover-highlight 來控制浮起與發光，解決點擊錯位 */
.spread-card.hover-highlight {
    z-index: 999999 !important;
    transform: rotate(var(--rot)) translateY(-35px) translate3d(0, 0, 80px) !important;
}

.spread-card.hover-highlight::before {
    transform: scale(1.15) !important; 
    filter: drop-shadow(0 0 16px #d4b5ff) drop-shadow(0 0 30px rgba(160, 132, 255, 0.8)) brightness(1.25) !important;
    border-color: #ffffff !important;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.95) !important;
}

/* 4. 手機版專用浮起微調 (配合螢幕尺寸縮小上浮範圍) */
@media screen and (max-width: 768px) {
    .spread-card.hover-highlight {
        transform: rotate(var(--rot)) translateY(-28px) translate3d(0, 0, 60px) !important;
    }
    .spread-card.hover-highlight::before {
        transform: scale(1.12) !important;
    }
}