/* --- 全域設定 --- */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: "Microsoft JhengHei", "Heiti TC", sans-serif;
    overflow: hidden;
    touch-action: none !important;
    overscroll-behavior: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.a-canvas {
    touch-action: none !important;
}

* {
    box-sizing: border-box;
}

/* --- 1. 彈出視窗 (Info Popup) --- */
.info-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    background: rgba(20, 20, 20, 0.98);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    color: white;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    touch-action: pan-y !important;
}

.info-popup.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.popup-close-x {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    color: #ddd;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2002;
    transition: all 0.2s;
    line-height: 1;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.popup-close-x:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: scale(1.1);
}

.popup-media-container {
    position: relative;
    width: 100%;
    height: 300px;
    background: #000;
    display: none;
    flex-shrink: 0;
    border-bottom: 1px solid #333;
}

.popup-media-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.popup-media-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.4);
    color: white;
    border: none;
    padding: 15px 10px;
    cursor: pointer;
    font-size: 20px;
    transition: 0.2s;
    user-select: none;
}

.nav-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.nav-btn.left {
    left: 0;
}

.nav-btn.right {
    right: 0;
}

.popup-content {
    padding: 25px;
}

.info-popup h2 {
    margin: 0 0 15px 0;
    font-size: 24px;
    color: #4aa3ff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
    padding-right: 30px;
}

.info-popup p {
    margin: 0 0 20px 0;
    line-height: 1.7;
    color: #ddd;
    font-size: 15px;
    white-space: pre-wrap;
}

.popup-audio {
    width: 100%;
    margin-top: 10px;
    margin-bottom: 10px;
    display: none;
    height: 40px;
}

@media screen and (max-height: 600px) and (orientation: landscape) {
    .info-popup {
        flex-direction: row;
        width: 85vw;
        max-width: 750px;
        height: 80vh;
        max-height: none;
        overflow: hidden;
    }

    .popup-media-container {
        width: 50%;
        height: 100%;
        border-bottom: none;
        border-right: 1px solid rgba(255, 255, 255, 0.15);
        background: #000;
    }

    .popup-media-container img {
        height: 100%;
        object-fit: contain;
    }

    .popup-content {
        flex: 1;
        height: 100%;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }
}

.overlay-mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(3px);
}

.overlay-mask.show {
    opacity: 1;
    pointer-events: auto;
}

/* --- 2. 地圖系統 --- */
#map-component {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    align-items: flex-end;
    z-index: 1500;
    transition: all 0.3s ease;
}

#mobile-map-btn {
    display: none;
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    color: white;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    z-index: 1502;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

#mobile-map-btn svg {
    width: 24px;
    height: 24px;
    fill: white;
}

#map-content-wrapper {
    display: flex;
    align-items: flex-end;
    transition: all 0.3s ease;
}

#map-display {
    position: relative;
    width: 280px;
    height: 180px;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-right: none;
    border-radius: 8px 0 0 8px;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 769px) and (min-height: 601px) {
    #map-component:hover #map-display {
        width: 500px;
        height: 350px;
    }
}

#map-image-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
    width: 100%;
    height: auto;
}

#current-map-img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
    opacity: 0.9;
}

#map-close-btn {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    z-index: 10;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.map-pin {
    position: absolute;
    width: 24px;
    height: 24px;
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0iI2UzM2UyZSIgZD0iTTEyIDJDNy41ODkgMiA0IDUuNTg5IDQgOS45OTVjMCAzLjk1MyAzLjY4NiA5LjIyNiA3LjM4NCAxMy43MjhsLjYxNi43NTFsLjYxNi0uNzUxQzE2LjMxNCAxOS4yMiAyMCAxMy45NDggMjAgOS45OTUgMjAgNS41ODkgMTYuNDExIDIgMTIgMnoiLz48Y2lyY2xlIGN4PSIxMiIgY3k9IjEwIiByPSIzLjUiIGZpbGw9IiNmZmZmZmYiLz48L3N2Zz4=');
    background-size: contain;
    background-repeat: no-repeat;
    transform: translate(-50%, -100%);
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 2;
    display: none;
}

.map-pin:hover {
    transform: translate(-50%, -100%) scale(1.3);
    z-index: 3;
}

.map-pin.active {
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZmlsbD0iI2ZmYjMwMCIgZD0iTTEyIDJDNy41ODkgMiA0IDUuNTg5IDQgOS45OTVjMCAzLjk1MyAzLjY4NiA5LjIyNiA3LjM4NCAxMy43MjhsLjYxNi43NTFsLjYxNi0uNzUxQzE2LjMxNCAxOS4yMiAyMCAxMy45NDggMjAgOS45OTUgMjAgNS41ODkgMTYuNDExIDIgMTIgMnoiLz48Y2lyY2xlIGN4PSIxMiIgY3k9IjEwIiByPSIzLjUiIGZpbGw9IiMwMDAiLz48L3N2Zz4=');
    animation: pinBounce 1.5s infinite;
    z-index: 4;
}

@keyframes pinBounce {

    0%,
    100% {
        transform: translate(-50%, -100%);
    }

    50% {
        transform: translate(-50%, -130%);
    }
}

#floor-nav {
    display: flex;
    flex-direction: column;
    background: rgba(30, 30, 30, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 0 8px 8px 0;
    overflow: hidden;
}

.floor-btn {
    width: 50px;
    min-height: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s;
    padding: 5px;
}

.floor-btn:hover {
    background: #444;
    color: white;
}

.floor-btn.active {
    background: #b30000;
    color: white;
}

/* --- 3. 一般 UI --- */
.scene-info {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    z-index: 999;
    pointer-events: none;
    font-size: 18px;
    letter-spacing: 2px;
    backdrop-filter: blur(5px);
}

#menu-toggle {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 999;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    font-size: 24px;
    padding: 10px 15px;
    border-radius: 8px;
    cursor: pointer;
}

#scene-menu {
    position: fixed;
    top: 0;
    left: -320px;
    width: 300px;
    height: 100%;
    background: rgba(15, 15, 15, 0.98);
    color: white;
    z-index: 998;
    transition: left 0.4s;
    padding: 80px 20px 20px;
    box-sizing: border-box;
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
}

#scene-menu.open {
    left: 0;
}

#scene-menu h3 {
    margin-bottom: 20px;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
}

#menu-list {
    list-style: none;
    padding: 0;
    overflow-y: auto;
    max-height: calc(100% - 60px);
}

#menu-list li {
    padding: 15px 10px;
    cursor: pointer;
    border-bottom: 1px solid #333;
    color: #ccc;
    transition: 0.2s;
}

#menu-list li:hover {
    background: #550000;
    color: #fff;
    padding-left: 15px;
}

.controls {
    position: fixed;
    top: 20px;
    left: 90px;
    bottom: auto;
    transform: none;
    display: flex;
    gap: 10px;
    z-index: 999;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 15px;
    border-radius: 8px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    align-items: center;
}

.controls button {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: 0.2s;
}

.controls button:hover {
    background: white;
    color: black;
    transform: scale(1.1);
}

/* --- 手機版與響應式調整 --- */

@media (max-width: 768px),
screen and (max-height: 600px) and (orientation: landscape) {
    #mobile-map-btn {
        display: flex;
    }

    #map-close-btn {
        display: flex;
    }

    .controls {
        top: 20px;
        left: 80px;
        bottom: auto;
        padding: 5px 12px;
        transform: none;
    }

    .controls button {
        width: 36px;
        height: 36px;
    }

    #map-component {
        bottom: 20px;
    }

    #map-content-wrapper {
        display: none;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        flex-direction: row;
        align-items: stretch;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
        max-width: 95vw;
    }

    #map-component.map-open {
        z-index: 2005 !important;
    }

    #map-component.map-open #map-content-wrapper {
        display: flex;
    }

    #floor-nav {
        border-radius: 0 8px 8px 0;
    }
}

@media (max-width: 768px) and (orientation: portrait) {
    #map-display {
        width: 85vw;
        height: auto;
        max-height: 60vh;
        border-radius: 8px 0 0 8px;
        border-right: none;
        background: #000;
    }
}

@media screen and (max-height: 600px) and (orientation: landscape) {
    #map-display {
        width: 45vw;
        max-width: 350px;
        height: auto;
        max-height: 85vh;
        border-radius: 8px 0 0 8px;
        border-right: none;
        background: #000;
    }
}

#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 9999;
    transition: opacity 0.8s;
    letter-spacing: 3px;
    font-weight: 300;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Fortune Modal Styles */
.modal {
    /* ★★★ 關鍵修正：預設隱藏，避免載入時直接顯示 ★★★ */
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    touch-action: pan-y !important;
}

/* 只有加上 .show 時才顯示，並設定 flex 置中 */
.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 0;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: 10px;
    position: relative;
    animation: animatetop 0.4s;
    max-height: 90vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

/* 抽籤狀態：往下移動 15% */
.modal-content.step-shake-mode {
    transform: translateY(15%);
}

@keyframes animatetop {
    from {
        opacity: 0;
        transform: translateY(-10%);
    }

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

.fortune-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #aaa;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
}

.fortune-close-btn:hover {
    color: #000;
}

.bwa-bwei-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    height: 100px;
    align-items: center;
}

.moon-block {
    width: 60px;
    height: 30px;
    background: #d32f2f;
    display: inline-block;
    transition: transform 0.5s;
}

.moon-block.flat-up {
    border-radius: 0 0 60px 60px;
    box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2) inset;
}

.moon-block.round-up {
    border-radius: 60px 60px 0 0;
    box-shadow: 0 -5px 5px rgba(0, 0, 0, 0.2) inset;
}

.moon-block.tossing {
    animation: toss 0.5s infinite linear;
}

@keyframes toss {
    0% {
        transform: rotateX(0deg) rotateY(0deg);
    }

    50% {
        transform: rotateX(180deg) rotateY(180deg);
    }

    100% {
        transform: rotateX(360deg) rotateY(360deg);
    }
}

.fortune-content {
    text-align: center;
    max-width: 400px;
}

.fortune-anim-box {
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 80px;
    margin: 20px 0;
}

.stick-container {
    animation: none;
}

.stick-container.shaking {
    animation: shake 0.5s infinite;
}

@keyframes shake {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.bwa-bwei {
    animation: none;
}

.bwa-bwei.throwing {
    animation: throw 1s ease-out;
}

@keyframes throw {
    0% {
        transform: translateY(0) rotate(0);
    }

    50% {
        transform: translateY(-50px) rotate(180deg);
    }

    100% {
        transform: translateY(0) rotate(360deg);
    }
}

#fortune-result-img-box {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 15px;
}

#fortune-result-img {
    width: 100%;
    height: auto;
    display: block;
}

.fortune-step {
    display: none;
}

#fortune-step-shake {
    display: block;
}

/* Fortune Card CSS */
:root {
    --fc-bg-color: #fcf9f0;
    --fc-border-color: #b8a398;
    --fc-theme-red: #a71e32;
    --fc-theme-gold: #9a834f;
    --fc-text-dark: #5d4037;
    --fc-text-light: #8d6e63;
}

.fortune-card-display {
    background: var(--fc-bg-color);
    color: var(--fc-text-dark);
    padding: 20px 15px;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
    position: relative;
    border: 2px solid var(--fc-border-color);
    font-family: "Kaiti TC", "STKaiti", "KaiTi", "BiauKai", "Georgia", serif;
    display: flex;
    flex-direction: column;
    justify-content: center;
    max-width: 360px;
    margin: auto;
}

.fc-header {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 15px;
    color: var(--fc-theme-gold);
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.fc-title::after {
    content: "·";
    margin: 0 8px;
}

.fc-status-box {
    display: table;
    margin: 0 auto 15px auto;
    background: var(--fc-theme-red);
    color: white;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 15px;
    letter-spacing: 2px;
    font-weight: normal;
}

.fc-main-text {
    font-size: 32px;
    font-weight: bold;
    color: var(--fc-theme-red);
    margin: 5px 0 20px 0;
    letter-spacing: 5px;
}

.fc-poem-box {
    display: flex;
    flex-direction: row-reverse;
    justify-content: center;
    gap: 20px;
    height: 140px;
    margin-bottom: 20px;
}

.fc-poem-line {
    writing-mode: vertical-rl;
    font-size: 18px;
    letter-spacing: 4px;
    line-height: 1.2;
    color: #333;
}

.fc-divider {
    height: 0;
    border-top: 1px dashed #d7ccc8;
    margin: 20px 0;
    opacity: 0.6;
}

.fc-explain-box {
    text-align: left;
    background: transparent;
    padding: 0 10px;
    font-size: 15px;
    line-height: 1.8;
    color: #666;
}

.fc-explain-title {
    font-weight: bold;
    color: var(--fc-theme-red);
    margin-bottom: 10px;
    font-size: 16px;
}

.fc-tags {
    margin-top: 15px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.fc-tag {
    background: #fbe9e7;
    color: var(--fc-theme-red);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 13px;
}

.fc-footer {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    color: var(--fc-text-light);
    padding-top: 10px;
    text-align: left;
    font-size: 13px;
}

.fc-stamp {
    width: 60px;
    height: 60px;
    border: 3px solid var(--fc-theme-red);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transform: rotate(-15deg);
    opacity: 0.8;
    font-size: 14px;
    line-height: 1.2;
    color: var(--fc-theme-red);
    font-weight: bold;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4' viewBox='0 0 4 4'%3E%3Cpath fill='%23a71e32' fill-opacity='0.2' d='M1 3h1v1H1V3zm2-2h1v1H3V1z'%3E%3C/path%3E%3C/svg%3E");
}

/* 按鈕樣式 */
.fortune-btn {
    background: linear-gradient(180deg, #d32f2f 0%, #b71c1c 100%);
    color: #fff;
    border: 1px solid #b71c1c;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.2s ease;
    font-family: "Microsoft JhengHei", "Heiti TC", sans-serif;
    letter-spacing: 2px;
    margin-top: 15px;
    text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.3);
    outline: none;
}

.fortune-btn:hover {
    background: linear-gradient(180deg, #e53935 0%, #c62828 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.fortune-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.fortune-btn:disabled,
.fortune-btn[disabled] {
    background: #888;
    border-color: #666;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* --- From index.html inline styles --- */

/* --- 1. 基礎設定 --- */
html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    touch-action: none;
    background-color: #000;
    font-family: "Microsoft JhengHei", sans-serif;
}

/* --- 2. Popup 樣式 --- */
.popup-text-content {
    font-size: 16px;
    line-height: 1.6;
    color: #eee;
    text-align: left;
    overflow-wrap: break-word;
}

.popup-text-content ul,
.popup-text-content ol {
    padding-left: 24px;
    margin: 10px 0;
}

.popup-text-content h1,
.popup-text-content h2 {
    color: #fff;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
}

.popup-text-content a {
    color: #4aa3ff;
    text-decoration: underline;
    cursor: pointer;
}

.popup-text-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 10px 0;
}

/* --- 3. 求籤視窗樣式 --- */
#fortune-modal {
    overflow-y: auto;
    z-index: 99999;
}

.fortune-content {
    margin: 80px auto 50px auto;
    max-width: 90%;
    width: 380px;
    position: relative;
    background-color: #ffffff !important;
    color: #333333 !important;
    border: 2px solid #e91e63;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.fortune-content h2 {
    color: #d81b60;
    border-bottom: 1px solid #eee;
    margin-top: 0;
}

.fortune-step p {
    color: #555;
    font-size: 16px;
    margin: 15px 0;
}

.fortune-close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    cursor: pointer;
    z-index: 10;
}

.fortune-close-btn:hover {
    color: #000;
}

.fortune-btn {
    background-color: #e91e63;
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 20px;
    cursor: pointer;
    margin-top: 10px;
}

.fortune-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* --- 4. 圖片與動畫樣式 --- */

/* 籤筒 */
.stick-container {
    width: 60px;
    height: auto;
    margin: 10px auto;
    position: relative;
    z-index: 5;
}

.stick-container img {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.3));
}

/* 筊杯容器 */
.bwa-bwei-container {
    display: flex;
    justify-content: center;
    gap: 60px;
    height: 180px;
    align-items: flex-end;
    padding-bottom: 20px;
    perspective: 800px;
    position: relative;
}

.moon-group {
    position: relative;
    width: 70px;
    height: 70px;
}



/* 【圖片與切換核心】 */
.moon-block {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 2;
    background-color: transparent !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center bottom;
    transform-origin: center center;

    /* 預設：正面 (平面) */
    background-image: url('../images/筊杯正面.png');

    /* 禁止過渡動畫，實現瞬間切圖 */
    transition: none !important;
}

/* 狀態：round-up (圓面/反面向上) */
.moon-block.round-up,
.moon-group.round-up .moon-block {
    /* 切換為：反面 (凸面) */
    background-image: url('../images/筊杯反面.png') !important;
}

/* ================================================================
   動畫階段 1: 拋擲 (Tossing Phase)
   ================================================================
*/

.moon-block.tossing {
    filter: blur(2px);
}

#block-1.tossing {
    animation: moon-toss-left 0.7s cubic-bezier(0.1, 0.6, 0.6, 1) forwards;
}

#block-2.tossing {
    animation: moon-toss-right 0.75s cubic-bezier(0.1, 0.6, 0.6, 1) forwards;
}

@keyframes moon-toss-left {
    0% {
        transform: translateY(0) scale(1) rotateX(0) rotateZ(0);
    }

    40% {
        transform: translateY(-140px) translateX(-20px) scale(1.4) rotateX(180deg) rotateZ(-45deg);
    }

    100% {
        /* 落地：回到原位，X軸轉兩圈回到正面(0度)，Z軸隨機 */
        transform: translateY(0) translateX(0) scale(1) rotateX(720deg) rotateZ(-180deg);
        filter: blur(0);
    }
}

@keyframes moon-toss-right {
    0% {
        transform: translateY(0) scale(1) rotateX(0) rotateZ(0);
    }

    45% {
        transform: translateY(-130px) translateX(20px) scale(1.4) rotateX(180deg) rotateZ(45deg);
    }

    100% {
        transform: translateY(0) translateX(0) scale(1) rotateX(720deg) rotateZ(180deg);
        filter: blur(0);
    }
}



/* ================================================================
   動畫階段 2: 落地回彈 (Bouncing Phase)
   ================================================================
*/

.moon-block.bouncing {
    animation: moon-bounce-physics 0.5s ease-out forwards;
}

#block-1.bouncing {
    --final-rot: -25deg;
    animation-duration: 0.5s;
}

#block-2.bouncing {
    --final-rot: 40deg;
    animation-delay: 0.05s;
    animation-duration: 0.55s;
}

@keyframes moon-bounce-physics {
    0% {
        transform: translateY(0) scale(1, 1) rotate(0);
    }

    15% {
        transform: translateY(0) scale(1.1, 0.85) rotate(0);
    }

    30% {
        transform: translateY(-20px) scale(0.95, 1.05) rotate(var(--final-rot));
    }

    50% {
        transform: translateY(0) scale(1.05, 0.95) rotate(var(--final-rot));
    }

    70% {
        transform: translateY(-5px) rotate(var(--final-rot));
    }

    100% {
        transform: translateY(0) rotate(var(--final-rot));
    }
}



/* 手機橫向調整 */
@media screen and (orientation: landscape) and (max-height: 600px) {

    /* 1. 修改外部容器對齊方式 */
    .modal.show {
        align-items: flex-start !important;
    }

    /* 2. 修改求籤視窗本體 */
    .fortune-content {
        width: 40% !important;
        margin-top: 30px !important;
        /* 上方留 10px，左右置中 */
        padding: 10px;
        max-height: 90vh;
        /* 確保不超過螢幕高度 */
    }

    .stick-container {
        width: 50px;
    }

    .moon-group {
        width: 50px;
        height: 50px;
    }

    .bwa-bwei-container {
        height: 140px;
        gap: 40px;
    }
}

/* --- 手機直式專用修正 (Mobile Portrait Fixes) --- */
@media (max-width: 768px) and (orientation: portrait) {

    /* 1. 修改外部容器對齊方式 */
    /* 原本是垂直置中(center)，改為從頂部開始(flex-start)，這樣才能精準控制往上移動 */
    .modal.show {
        align-items: flex-start !important;
    }

    /* 2. 修改求籤視窗本體 */
    .fortune-content {
        /* 【左右變窄】 */
        width: 80% !important;
        /* 從原本的 90% 改為 80%，讓兩側留白更多 */
        max-width: 320px !important;
        /* 限制最大寬度，避免在較大手機上太寬 */

        /* 【整體往上】 */
        /* 15vh 代表距離螢幕頂部 15% 的高度 (原本可能是置中或固定 80px) */
        /* 您可以調整 15vh 這個數字，越小越靠上，越大越靠下 */
        margin: 15vh auto 20px auto !important;
    }
}