/* 基本頁面樣式 */
:root {
    --primary-color: #3498db;
    --secondary-color: #e74c3c;
    --bg-color: #2c3e50;
    --container-color: #34495e;
    --text-color: #ecf0f1;
    --card-width: min(150px, 20vw);
}

body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: clamp(12px, 2vh, 24px) clamp(12px, 3vw, 24px);
    background-attachment: fixed;
    background-size: cover;
}

.app-container {
    text-align: center;
    background-color: var(--container-color);
    padding: clamp(16px, 3vh, 24px) clamp(16px, 4vw, 32px);
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    width: min(95%, 1400px);
    box-sizing: border-box;
    margin: clamp(10px, 2vh, 20px) auto;
}

h1 {
    font-size: clamp(1.8rem, 5vw, 2.5rem);
    margin-bottom: clamp(12px, 2.5vh, 24px);
    line-height: clamp(1.2, 1.3, 1.4);
    letter-spacing: -0.02em;
    font-weight: 600;
}

#status-text {
    font-size: clamp(1rem, 3vw, 1.2rem);
    margin-bottom: clamp(16px, 3.5vh, 28px);
    line-height: clamp(1.4, 1.6, 1.8);
    max-width: min(90%, 800px);
    margin-left: auto;
    margin-right: auto;
    color: rgba(236, 240, 241, 0.9);
}

/* 牌陣選擇 */
#spread-selection {
    margin-bottom: clamp(16px, 3vh, 24px);
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: clamp(8px, 1.5vw, 12px);
}

.spread-choice-btn {
    background-color: #3498db;
    margin: 0 clamp(8px, 1.5vw, 12px);
    min-width: clamp(100px, 15vw, 140px);
}

.spread-choice-btn.selected {
    background-color: #e74c3c; /* 與主按鈕顏色一致 */
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(231, 76, 60, 0.6); /* 調整陰影顏色以匹配 */
    z-index: 1;
}

/* 卡牌與結果區 */
#game-board {
    min-height: 600px; /* 調整高度以適應縮小的牌陣 */
    /* 移除 flex 屬性，讓內部元素可以透過 margin: auto 置中 */
}

#result-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 50px; /* 左右兩區的間距 */
    width: 100%;
}

.card-placeholder {
    text-align: center;
    position: relative;
}

.card-label { font-size: 1.1em; margin-bottom: 10px; color: #bdc3c7; }

/* 響應式卡片樣式 */
#result-container img {
    width: var(--card-width);
    height: calc(var(--card-width) * 1.4); /* 保持 1:1.4 的卡片比例 */
    object-fit: contain; /* 修改這裡以完整顯示圖片 */
    border: none; /* 取消框線 */
    border-radius: calc(var(--card-width) * 0.06);
    box-shadow: none; /* 取消陰影 */
    transition: all 0.3s ease;
    margin: 0 clamp(2px, 0.8vw, 8px);
    will-change: transform; /* 優化動畫效能 */
}

/* 卡片懸停效果 */
#result-container img:hover {
    transform: scale(1.05);
    box-shadow: none; /* 取消懸停時的陰影 */
    z-index: 10;
}

#result-container img.reversed { transform: rotate(180deg); }

/* 控制按鈕 */
button#shuffle-button {
    margin-bottom: 20px; /* 與下方遊戲區的間距 */
}

.controls { margin-top: 20px; }
button {
    background-color: #e74c3c;
    color: white;
    border: none;
    padding: clamp(12px, 1.5vh, 16px) clamp(16px, 3vw, 24px);
    font-size: clamp(16px, 1.8vw, 18px);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin: 0 clamp(5px, 1vw, 10px);
    min-width: clamp(100px, 15vw, 140px);
    min-height: clamp(36px, 5vh, 44px);
    touch-action: manipulation; /* 優化觸控體驗 */
}

@media (hover: hover) {
    button:hover:not(:disabled) {
        background-color: #c0392b;
        transform: scale(1.05);
    }
}

@media (hover: none) {
    button:active:not(:disabled) {
        background-color: #c0392b;
        transform: scale(0.98);
    }
}

button:disabled { background-color: #95a5a6; cursor: not-allowed; }

.hidden { display: none !important; }

/* 等待抽牌的牌背圖示 */
#deck-placeholder {
    margin-top: 50px; /* 與上方文字的間距 */
}

#deck-placeholder img {
    width: 180px; /* 比結果牌稍大 */
    border: 5px solid #95a5a6;
    border-radius: 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

/* 洗牌動畫 */
#shuffle-animation-container { position: relative; width: 150px; height: 260px; margin: 40px auto 0; left: -70px; }
.shuffling-card { position: absolute; width: 150px; animation: shuffle 1s infinite ease-in-out; }
@keyframes shuffle {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-40px, -20px) rotate(-10deg); }
    50% { transform: translate(0, 20px) rotate(0deg); }
    75% { transform: translate(40px, -20px) rotate(10deg); }
}

/* --- 聖三角佈局 --- */
.holy-triangle-layout {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 2vw;
    margin: 2vh auto;
    padding: 0;
    width: 100%;
    max-width: 100%;
    position: relative;
    transform: scale(0.9);
}

/* --- 賽爾特十字牌陣佈局 --- */
.celtic-cross-layout {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 1vw; /* 縮小間距 */
    width: 100%;
    margin: 2vh auto;
    position: relative;
    transform: scale(0.95);
}

.celtic-cross-cross {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1.5vh 4.5vw;
    width: min(90vw, 600px);
    height: min(90vw, 600px);
    align-items: center;
    justify-items: center;
    position: relative;
}

.celtic-cross-staff {
    display: flex;
    flex-direction: column-reverse;
    justify-content: center;
    gap: 1.5vh;
    width: calc(var(--card-width) * 1.2);
}

/* 十字區卡牌位置 */
.celtic-cross-card-1 { grid-area: 2 / 2 / 3 / 3; z-index: 1; }
.celtic-cross-card-2 {
    grid-area: 2 / 2 / 3 / 3;
    z-index: 2;
    transform: rotate(-90deg);
    position: relative;
    top: 10vh;
}
.celtic-cross-card-3 { grid-area: 1 / 2 / 2 / 3; }
.celtic-cross-card-4 { grid-area: 3 / 2 / 4 / 3; position: relative; top: 2vh; }
.celtic-cross-card-5 { grid-area: 2 / 1 / 3 / 2; }
.celtic-cross-card-6 { grid-area: 2 / 3 / 3 / 4; }

/* 逆位牌在賽爾特十字中的特殊旋轉 */
.celtic-cross-card-2.reversed { transform: rotate(-90deg) rotate(180deg); }

/* 響應式調整 */
@media (max-width: 768px) {
    .app-container {
        padding: 2vh 3vw;
        width: 98%;
        margin: 1vh auto;
    }

    h1 {
        line-height: 1.2;
        margin-bottom: clamp(10px, 2vh, 20px);
    }

    #status-text {
        line-height: 1.5;
        margin-bottom: clamp(12px, 3vh, 24px);
    }

    .spread-choice-btn {
        margin: 0 clamp(4px, 1.5vw, 8px) !important;
        min-width: clamp(90px, 20vw, 120px);
    }

    #result-container img {
        margin: 0 1vw;
        width: min(130px, 22vw);
    }

    /* Mobile-specific layout rules updated to maintain desktop presentation. */
    .holy-triangle-layout {
        transform: scale(0.85);
    }

    .celtic-cross-layout {
        transform: scale(0.8);
        gap: 0; /* 在手機上進一步縮小間距 */
    }

    .celtic-cross-cross {
        position: static;
        gap: 1.5vh 1vw; /* 縮小十字內部的水平間距 */
    }

    .celtic-cross-staff {
        margin-left: -8vw; /* 將右側區塊向左拉近 */
    }

    button {
        padding: clamp(10px, 1.8vh, 14px) clamp(12px, 4vw, 20px);
        font-size: clamp(14px, 2.2vw, 16px);
        min-width: clamp(90px, 20vw, 120px);
    }
}

@media (max-width: 480px) {
    #result-container img {
        border-width: max(0.5px, calc(var(--card-width) * 0.02));
        margin: 0 clamp(1px, 0.5vw, 4px);
        width: min(110px, 25vw);
    }

    .holy-triangle-layout {
        transform: scale(0.75);
        gap: 4vw;
    }

    .celtic-cross-layout {
        /* The column layout from 768px is already active */
    }
    
    .celtic-cross-cross {
        /* The column layout from 768px is already active */
    }
    
    .celtic-cross-card-2 {
        /* The column layout from 768px is already active */
    }
}