/* --- 全域設定 --- */
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;
    pointer-events: none;
    /* Don't block scene when closed */
}

#map-component>* {
    pointer-events: auto;
    /* Re-enable for child elements */
}

#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;
    /* Square dimensions */
    width: 250px;
    height: 250px;
    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 {
        /* Square hover dimensions */
        width: 450px;
        height: 450px;
    }
}

#map-image-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
    width: 100%;
    height: 100%;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

@media (min-width: 769px) and (min-height: 601px) {
    #map-component:hover #map-image-wrapper {
        width: 100%;
        height: 100%;
    }
}

#current-map-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    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: 80px;
    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;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* ... */

.controls {
    position: fixed;
    top: 20px;
    left: 80px;
    /* Adjusted to be closer to equal spacing */
    bottom: auto;
    transform: none;
    display: flex;
    gap: 10px;
    z-index: 999;
    /* remove container bg/padding to let button stand alone like menu */
    background: transparent;
    padding: 0;
    border-radius: 0;
    backdrop-filter: none;
    border: none;
    align-items: center;
}

.controls button {
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    /* Remove border to match menu style */
    width: 44px;
    height: 44px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    /* Match menu icon size approx */
    transition: 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

/* New Scene Menu Styles */
#scene-menu {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100%;
    /* Glassmorphism background */
    background: linear-gradient(135deg, rgba(20, 20, 20, 0.95), rgba(40, 40, 40, 0.98));
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    z-index: 998;
    transition: left 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    padding: 80px 20px 20px;
    box-sizing: border-box;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.6);
}

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

#scene-menu h3 {
    margin-bottom: 25px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    padding-bottom: 15px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 1px;
    color: #fff;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#menu-list {
    list-style: none;
    padding: 0 5px;
    /* Add slight padding for hover effects */
    overflow-y: auto;
    max-height: calc(100% - 80px);
    /* Custom Scrollbar for Webkit */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#menu-list::-webkit-scrollbar {
    width: 6px;
}

#menu-list::-webkit-scrollbar-track {
    background: transparent;
}

#menu-list li:not(.menu-category-header) {
    padding: 16px 20px;
    margin-bottom: 12px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: #ddd;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    font-size: 16px;
    position: relative;
    overflow: hidden;
}

#menu-list li:not(.menu-category-header)::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #d32f2f;
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

#menu-list li:not(.menu-category-header):hover {
    background: linear-gradient(90deg, rgba(211, 47, 47, 0.15), rgba(255, 255, 255, 0.05));
    color: #fff;
    transform: translateX(5px) scale(1.02);
    border-color: rgba(211, 47, 47, 0.3);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    padding-left: 25px;
}

#menu-list li:not(.menu-category-header):hover::before {
    transform: scaleY(1);
}

#menu-list li:not(.menu-category-header).active {
    background: linear-gradient(90deg, rgba(211, 47, 47, 0.3), rgba(255, 255, 255, 0.05));
    border-color: #d32f2f;
    color: #fff;
}

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

@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;
        pointer-events: auto;
        /* Enable interaction when map is open */
    }

    #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: 140px;
    /* Reduced to fit tighter layout */
    display: flex;
    align-items: center;
    /* Vertically center the container */
    justify-content: center;
    font-size: 80px;
    margin: 10px 0;
    overflow: visible;
    /* Don't clip the cups */
    position: relative;
    width: 100%;
}

.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: 20px;
    font-size: 18px;
    font-weight: bold;
    letter-spacing: 5px;
}

.fc-poem-box {
    display: flex;
    flex-direction: row-reverse;
    justify-content: center;
    gap: 20px;
    height: 220px;
    /* Increased from 140px to fit 7-char vertical text */
    margin-bottom: 20px;
}

.fc-poem-line {
    writing-mode: vertical-rl;
    font-size: 24px;
    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;
}



/* 按鈕樣式 */
.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: 120px;
    /* Reduced to move cups up */
    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(-80px) translateX(-10px) scale(1.2) 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(-70px) translateX(10px) scale(1.2) 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;
    }
}

/* Settings Button & Modal */
#settings-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#settings-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    transform: rotate(90deg);
}

.settings-content {
    text-align: left;
    max-width: 500px;
    padding: 30px;
    line-height: 1.8;
}

.settings-content h2 {
    color: #4aa3ff;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    margin-top: 0;
}

.settings-body p {
    font-size: 16px;
    color: #444;
    margin-bottom: 15px;
}

.settings-close-btn {
    position: absolute;
    right: 20px;
    top: 15px;
    font-size: 30px;
    cursor: pointer;
    color: #aaa;
    transition: color 0.2s;
}

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

/* Glass Transition Overlay */
/* Black Transition Overlay */
#transition-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;

    /* Flex Center */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 300;
    letter-spacing: 2px;
    /* Solid Black */
    z-index: 1000000;
    /* Ensure it covers everything including loading screen */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

body.transition-active #transition-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* Transparent Loading State */
#loading-screen.loading-transparent {
    background: rgba(0, 0, 0, 0.4);
    /* Dark dim instead of full black */
    backdrop-filter: none;
    /* No expensive blur */

    /* ================================================================
   動畫階段 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;
        }
    }

    /* Settings Button & Modal */
    #settings-btn {
        position: absolute;
        top: 20px;
        right: 20px;
        z-index: 1000;
        background: rgba(0, 0, 0, 0.6);
        color: white;
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        width: 44px;
        height: 44px;
        font-size: 24px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
    }

    #settings-btn:hover {
        background: rgba(255, 255, 255, 0.9);
        color: #333;
        transform: rotate(90deg);
    }

    .settings-content {
        text-align: left;
        max-width: 500px;
        padding: 30px;
        line-height: 1.8;
    }

    .settings-content h2 {
        color: #4aa3ff;
        border-bottom: 2px solid #eee;
        padding-bottom: 10px;
        margin-top: 0;
    }

    .settings-body p {
        font-size: 16px;
        color: #444;
        margin-bottom: 15px;
    }

    .settings-close-btn {
        position: absolute;
        right: 20px;
        top: 15px;
        font-size: 30px;
        cursor: pointer;
        color: #aaa;
        transition: color 0.2s;
    }

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

    /* Glass Transition Overlay */
    /* Black Transition Overlay */
    #transition-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: #000;
        /* Solid Black */
        z-index: 9998;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.4s ease;
    }

    body.transition-active #transition-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    /* Transparent Loading State */
    #loading-screen.loading-transparent {
        background: rgba(0, 0, 0, 0.4);
        /* Dark dim instead of full black */
        backdrop-filter: none;
        /* No expensive blur */
        -webkit-backdrop-filter: none;
        transition: opacity 0.2s;
    }

    /* CSS for Menu Categories */
    .menu-category-header {
        background: transparent;
        color: #d32f2f;
        /* Temple Red Accent */
        font-weight: bold;
        padding: 20px 10px 8px 5px;
        cursor: default;
        pointer-events: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        font-size: 15px;
        margin-top: 10px;
        letter-spacing: 1px;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }

    .menu-category-header:first-child {
        margin-top: 0;
    }
}

/* Mobile Info Popup Adjustment */
@media (max-width: 600px) {
    .info-popup {
        width: 85%;
        max-height: 80vh;
    }

    .popup-content {
        padding: 20px;
    }

    .info-popup h2 {
        font-size: 20px;
    }
}

/* Audio Control Button */
#popupAudioControl {
    display: none;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 6px 14px;
    border-radius: 20px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    letter-spacing: 0.5px;
}

#popupAudioControl:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.4);
}

#popupAudioControl:active {
    transform: translateY(1px);
    box-shadow: none;
}

#popupAudioControl.playing {
    background: rgba(74, 163, 255, 0.2);
    border-color: #4aa3ff;
    color: #4aa3ff;
    box-shadow: 0 0 15px rgba(74, 163, 255, 0.2);
}

#popupAudioControl.playing #audioIcon {
    animation: soundWave 1.2s infinite ease-in-out;
}

@keyframes soundWave {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }
}

#audioIcon {
    font-size: 14px;
}

/* Custom Audio Player */
#customAudioPlayer {
    backdrop-filter: blur(5px);
    transition: all 0.3s ease;
}

#customPlayBtn:hover {
    color: #4aa3ff;
    transform: scale(1.1);
}

/* Styled Range Input */
#audioProgress {
    -webkit-appearance: none;
    background: transparent;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
    position: relative;
    outline: none;
}

#audioProgress::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 12px;
    width: 12px;
    border-radius: 50%;
    background: #4aa3ff;
    cursor: pointer;
    margin-top: -4px;
    box-shadow: 0 0 10px rgba(74, 163, 255, 0.5);
    transition: transform 0.1s;
}

#audioProgress::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

#audioProgress::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: transparent;
    border-radius: 2px;
}

/* Beautify Transition Overlay Spinner (Premium Glow) */
#transition-overlay .loading-spinner {
    width: 50px;
    height: 50px;
    border: 2px solid transparent;
    border-radius: 50%;
    border-top-color: #fff;
    border-left-color: rgba(255, 255, 255, 0.5);
    margin-bottom: 20px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    animation: spin-glow 1s linear infinite;
}

#transition-overlay div:last-child {
    font-size: 14px !important;
    font-weight: 300;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 4px;
    animation: text-pulse 1.5s ease-in-out infinite alternate;
}

@keyframes spin-glow {
    0% {
        transform: rotate(0deg);
        box-shadow: 0 0 5px rgba(255, 255, 255, 0.1);
    }

    50% {
        transform: rotate(180deg);
        box-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
    }

    100% {
        transform: rotate(360deg);
        box-shadow: 0 0 5px rgba(255, 255, 255, 0.1);
    }
}

@keyframes text-pulse {
    from {
        opacity: 0.5;
        letter-spacing: 4px;
    }

    to {
        opacity: 1;
        letter-spacing: 5px;
    }
}