/* 基本樣式與字體 */
body {
    font-family: 'Arial', 'Microsoft JhengHei', sans-serif;
    line-height: 1.4;
    padding: 5px;
    background-color: #e3d3b7; /* 預設羊皮紙底色，防止載入背景圖前出現白頻 */
    background-image: url('images/自然史風1.webp');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: #333;
}

/* 半透明外層包裝 */
.game-wrapper {
    max-width: 900px;
    margin: 0 auto;
    padding: 8px 16px;
    background: rgba(244, 236, 216, 0.88);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(139, 69, 19, 0.3);
}

h1,
h2 {
    text-align: center;
    color: #4a2e15;
}

h1 {
    margin-top: 0;
    margin-bottom: 8px;
    font-size: 2.2em;
}

p {
    text-align: center;
    margin-bottom: 8px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    color: #5c3a21;
}

/* 遊戲容器佈局 (改為垂直堆疊) */
.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 5px;
    padding: 0;
    background-color: transparent;
    border-radius: 10px;
    box-shadow: none;
}

/* 輪廓和蛋的容器 (垂直堆疊設定) */
.outlines-container,
.eggs-container {
    width: 100%;
    max-width: 800px;
    padding: 10px;
    border: 2px dashed rgba(139, 69, 19, 0.3);
    border-radius: 8px;
    text-align: center;
}

.eggs-container {
    padding: 8px 12px;
    position: relative;
}

.eggs-container .description {
    margin-top: 0;
    margin-bottom: 6px;
    font-size: 0.95em;
    font-weight: bold;
}

.outlines-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
}

.outlines-container h2 {
    width: 100%;
    flex-shrink: 0;
}

.outlines-container h2,
.eggs-container h2 {
    margin-top: 0;
    margin-bottom: 6px;
    font-size: 1.1em;
    color: #555;
    transition: color 0.3s ease;
}

/* --- 輪廓和內部元素的樣式 (結合絕對定位需求) --- */

.outline-wrapper {
    display: inline-block;
    /* 讓輪廓可以並排 */
    margin: 10px;
    padding: 5px;
    vertical-align: top;
    perspective: 1000px;
    /* 新增 3D 視角 */
}

/* 輪廓樣式 - 轉為 3D 翻轉容器 */
.outline {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* 確保寬高由內部 card-front 決定 */
}

/* 觸發翻轉的類別 */
.outline.flipped {
    transform: rotateY(180deg);
}

/* 卡牌正反面共用樣式 */
.card-front,
.card-back {
    box-sizing: border-box;
    border: 1px solid #8b5a2b;
    /* 復古深棕色外框 */
    border-radius: 4px;
    /* 紙卡微圓角 */
    background-color: #f4ecd8;
    /* 羊皮紙底色 */
    box-shadow: inset 0 0 20px rgba(139, 69, 19, 0.15), 2px 4px 8px rgba(0, 0, 0, 0.2);
    backface-visibility: hidden;
    position: relative;
    overflow: hidden;
}

/* 內層裝飾線框 (增添復古感) */
.card-front::before,
.card-back::before {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    bottom: 6px;
    left: 6px;
    border: 1px solid rgba(139, 69, 19, 0.4);
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

/* 卡牌正面特有樣式 */
.card-front {
    width: 140px;
    height: 210px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px 10px;
    text-align: center;
    z-index: 2;
    /* 正面朝上 */
}

/* 卡牌背面特有樣式 */
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotateY(180deg);
    /* 初始翻轉 180 度隱藏 */
    background-color: #e2d5b8;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px 10px;
    text-align: center;
}

/* 背面鳥類圖片樣式 */
.card-back .bird-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.9;
    filter: sepia(0.2) contrast(1.1);
    /* 輕微復古感與對比度 */
}

/* 翻牌提示圖示 (置頂正中) — 共用基本樣式 */
.card-front .flip-hint,
.card-back .flip-hint {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.3em;
    color: rgba(244, 236, 216, 0.85);
    background: rgba(92, 58, 33, 0.55);
    width: 28px;
    height: 28px;
    line-height: 28px;
    text-align: center;
    border-radius: 50%;
    z-index: 12;
    pointer-events: none;
    animation: hintPulse 2s ease-in-out infinite;
}

/* 正面的翻牌提示：遊戲進行中隱藏 */
.card-front .flip-hint {
    display: none;
}

/* 配對完成後才顯示正面的翻牌提示 */
.outline.matched .card-front .flip-hint {
    display: block;
}

@keyframes hintPulse {

    0%,
    100% {
        opacity: 0.7;
        transform: translateX(-50%) scale(1);
    }

    50% {
        opacity: 1;
        transform: translateX(-50%) scale(1.15);
    }
}

/* 輪廓內的圖片 (outline-image) */
.card-front .outline-image {
    max-width: 65px;
    height: auto;
    opacity: 0.4;
    filter: sepia(0.5) hue-rotate(-10deg);
    margin-bottom: 0;
    transition: opacity 0.3s ease;
    position: relative;
    z-index: 0;
}

/* 輪廓內的文字 */
.card-front span {
    font-size: 0.95em;
    font-family: 'Times New Roman', serif;
    font-weight: bold;
    letter-spacing: 1px;
    color: #5c3a21;
    position: absolute;
    bottom: 12px;
    left: 0;
    width: 100%;
    z-index: 0;
}

/* 當有東西拖曳到輪廓上方時的樣式 */
.outline.drag-over .card-front {
    background-color: #e8dcb8;
    border-color: #5c3a21;
    transform: translateY(-3px);
    box-shadow: inset 0 0 20px rgba(139, 69, 19, 0.2), 4px 8px 12px rgba(0, 0, 0, 0.25);
}

/* 當輪廓已成功配對時的樣式 */
.outline.matched .card-front {
    border-style: solid;
    border-color: #4a2e15;
    background-color: #e2d5b8;
    box-shadow: inset 0 0 15px rgba(139, 69, 19, 0.1), 1px 2px 4px rgba(0, 0, 0, 0.15);
}

/* 配對成功後，輪廓圖片變淡 */
.outline.matched .card-front .outline-image {
    opacity: 0.15;
}

/* 配對成功後，放在輪廓內的蛋圖片的樣式 (絕對定位疊加) */
.outline.matched .draggable-egg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    width: 80px;
    height: auto;
    opacity: 1;
    cursor: pointer;
    /* 讓整個區域都顯示可點擊 */
    margin: 0;
    backface-visibility: hidden;
    /* 確保卡牌翻轉時蛋也會隱藏 */
}

/* 讓已配對的輪廓也顯示為可點擊 */
.outline.matched {
    cursor: pointer;
}

/* --- 可拖曳的蛋的樣式 (在右側容器中時) --- */
.eggs-container img.draggable-egg {
    width: 65px;
    height: auto;
    cursor: grab;
    margin: 4px 8px;
    transition: transform 0.2s ease, opacity 0.2s ease;
    vertical-align: middle;
}

/* 正在被拖曳的蛋的樣式 (不變) */
.draggable-egg.dragging {
    opacity: 0.5;
    /*transform: scale(1.1);*/
    cursor: grabbing;
}

/* 頂部虛線框的過關橫幅 */
#completion-banner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 510px;
    box-sizing: border-box;
    background: linear-gradient(135deg, #5c3a21, #8b5a2b, #5c3a21);
    color: #f4ecd8 !important;
    font-size: 1.1em;
    font-weight: bold;
    padding: 10px 20px;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(92, 58, 33, 0.4);
    border: 1px solid rgba(244, 236, 216, 0.3);
    letter-spacing: 1px;
    animation: bannerFadeIn 0.5s ease-out;
}

@keyframes bannerFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#reset-button {
    display: none; /* 配對完成前隱藏 */
    margin: 8px auto;
    padding: 8px 24px;
    font-size: 1em;
    color: #f4ecd8;
    background-color: #7a4a1e;
    border: 2px solid #5c3a15;
    border-radius: 6px;
    cursor: pointer;
    letter-spacing: 1px;
    transition: background-color 0.3s ease, transform 0.15s ease;
    box-shadow: 0 3px 8px rgba(92, 58, 21, 0.35);
}

#reset-button:hover {
    background-color: #5c3a15;
    transform: translateY(-1px);
}

/* RWD Media Query: 手機版面優化 */
@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .game-wrapper {
        padding: 12px 10px;
    }

    h1 {
        font-size: 1.3em;
    }

    p {
        font-size: 0.85em;
        margin-bottom: 10px;
    }

    .game-container {
        gap: 10px;
        padding: 5px;
    }

    .outlines-container,
    .eggs-container {
        padding: 6px;
        margin-bottom: 5px;
    }

    /* 輪廓容器保持橫排 */
    .outlines-container {
        gap: 4px;
    }

    .outlines-container h2,
    .eggs-container h2 {
        font-size: 0.95em;
        margin-bottom: 4px;
    }

    .outline-wrapper {
        margin: 3px;
        padding: 2px;
    }

    /* 縮小卡片 */
    .card-front,
    .card-back {
        width: 90px;
        min-height: 110px;
        padding: 6px;
    }

    .card-front .outline-image {
        max-width: 50px;
    }

    .card-front span:not(.flip-hint) {
        font-size: 0.7em;
    }

    .eggs-container img.draggable-egg,
    .outline.matched .draggable-egg {
        width: 50px;
        margin: 3px;
    }

    /* 翻牌提示縮小 */
    .card-front .flip-hint,
    .card-back .flip-hint {
        width: 22px;
        height: 22px;
        line-height: 22px;
        font-size: 1em;
    }

    /* 完成橫幅縮小 */
    #completion-banner {
        font-size: 1em;
        padding: 8px 12px;
    }
}

/* 頁尾標示 (典藏者) */
.footer {
    text-align: center;
    font-size: 0.8em;
    color: #7a4a1e;
    margin-top: 15px;
    padding: 0;
    opacity: 0.8;
}