:root {
    --bg-color: #2c1e16;
    --paper-color: #f4e8d1;
    --paper-dark: #d8c3a5;
    --text-color: #3e2723;
    --gold: #c59b27;
    --gold-light: #e8c766;
    --red-wax: #8b0000;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Noto Serif TC', serif;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.background-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(44, 30, 22, 0) 0%, rgba(20, 10, 5, 1) 100%);
    pointer-events: none;
    z-index: 0;
}

.hidden-initially {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.start-video-btn {
    font-size: 1.5rem;
    padding: 20px 50px;
}

/* 開場動畫 (海浪與文字) */
.intro-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 1s ease-in-out;
}

/* 持續存在的焦點鎖頭 */
#persistent-lock {
    position: fixed;
    z-index: 105;
    transition: all 1.5s cubic-bezier(0.25, 1, 0.5, 1);
}

#persistent-lock.center-stage {
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1.2);
}

/* 海浪過場與星星 */
.stars {
    position: absolute;
    width: 100%;
    height: 100%;
    background: transparent;
    pointer-events: none;
    z-index: 0;
}

.stars::after {
    content: '';
    position: absolute;
    top: 20%;
    left: 10%;
    width: 3px;
    height: 3px;
    background: var(--gold-light);
    box-shadow:
        15vw 30vh 0 var(--gold),
        50vw 15vh 0 var(--gold-light),
        80vw 45vh 0 var(--gold),
        65vw 60vh 0 var(--gold-light),
        25vw 70vh 0 var(--gold-light),
        85vw 80vh 0 var(--gold);
    border-radius: 50%;
    animation: twinkle 3s ease-in-out infinite alternate;
}

@keyframes twinkle {
    0% {
        opacity: 0.3;
        transform: scale(0.8);
    }

    100% {
        opacity: 1;
        transform: scale(1.2);
        box-shadow:
            15vw 30vh 0 2px rgba(197, 155, 39, 0.5),
            50vw 15vh 0 1px rgba(232, 199, 102, 0.8),
            80vw 45vh 0 2px rgba(197, 155, 39, 0.6),
            65vw 60vh 0 1px rgba(232, 199, 102, 0.5),
            25vw 70vh 0 2px rgba(232, 199, 102, 0.7),
            85vw 80vh 0 1px rgba(197, 155, 39, 0.4);
    }
}

.ocean-waves {
    position: absolute;
    bottom: -50px;
    width: 200%;
    height: 35%;
    background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 1200 120" xmlns="http://www.w3.org/2000/svg"><path d="M0,0V46.29c47.79,22.2,103.59,32.17,158,28,70.36-5.37,136.33-33.31,206.8-37.5C438.64,32.43,512.34,53.67,583,72.05c69.27,18,138.3,24.88,209.4,13.08,36.15-6,69.85-17.84,104.45-29.34C989.49,25,1113-14.29,1200,52.47V0Z" fill="%23c59b27" opacity=".3"/><path d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z" fill="%234A2E1B" opacity=".7"/></svg>') repeat-x;
    background-size: 50% 100%;
    animation: waveMotion 6s linear infinite;
    opacity: 0;
    animation: fadeInOutWaves 4s cubic-bezier(0.36, 0, 0.66, -0.56) forwards;
}

.wave-layer2 {
    bottom: -80px;
    height: 45%;
    background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 1200 120" xmlns="http://www.w3.org/2000/svg"><path d="M0,0V15.81C13,36.92,27.64,56.86,47.69,72.05,99.41,111.27,165,111,224.58,91.58c31.15-10.15,60.09-26.07,89.67-39.8,40.92-19,84.73-46,130.83-49.67,36.26-2.85,70.9,9.42,98.6,31.56,31.77,25.39,62.32,62,103.63,73,40.44,10.79,81.35-6.69,119.13-24.28s75.16-39,116.92-43.05c59.73-5.85,113.28,22.88,168.9,38.84,30.2,8.66,59,6.17,87.09-7.5,22.43-10.89,48-26.93,60.65-49.24V0Z" fill="%232c1e16" opacity="0.95"/></svg>') repeat-x;
    background-size: 50% 100%;
    animation: waveMotion 4s linear infinite reverse, fadeInOutWaves2 4s ease-out forwards;
    z-index: 10;
}

.intro-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 101;
}

.intro-lock {
    width: 60px;
    height: 80px;
    position: relative;
}

.lock-shackle {
    width: 34px;
    height: 44px;
    border: 8px solid var(--gold);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    position: absolute;
    top: -5px;
    left: 5px;
    transform-origin: left bottom;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.lock-body {
    width: 65px;
    height: 50px;
    background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 50%, #9e7b1a 100%);
    border-radius: 8px;
    position: absolute;
    bottom: 0;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8), inset 0 2px 4px rgba(255, 255, 255, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid #856612;
}

.keyhole {
    width: 12px;
    height: 12px;
    background-color: var(--text-color);
    border-radius: 50%;
    position: relative;
    box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.8);
}

.keyhole::after {
    content: '';
    position: absolute;
    top: 8px;
    left: 2px;
    width: 8px;
    height: 14px;
    background-color: var(--text-color);
    clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
    box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.8);
}

.intro-text {
    font-size: 2rem;
    color: var(--gold-light);
    letter-spacing: 5px;
    display: flex;
    text-shadow: 0 2px 10px rgba(197, 155, 39, 0.5);
    margin-top: 50px;
}

.intro-text span {
    opacity: 0;
    transform: translateY(20px);
    animation: letterFadeIn 0.8s forwards;
}

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

@keyframes waveMotion {
    to {
        transform: translateX(-50%);
    }
}

@keyframes fadeInOutWaves {
    0% {
        opacity: 0;
        bottom: -100px;
    }

    20% {
        opacity: 1;
        bottom: -20px;
    }

    80% {
        opacity: 1;
        bottom: -20px;
    }

    100% {
        opacity: 0;
        bottom: -100px;
    }
}

.intro-text span:nth-child(1) {
    animation-delay: 0.5s;
}

.intro-text span:nth-child(2) {
    animation-delay: 0.7s;
}

.intro-text span:nth-child(3) {
    animation-delay: 0.9s;
}

.intro-text span:nth-child(4) {
    animation-delay: 1.1s;
}

.intro-text span:nth-child(5) {
    animation-delay: 1.3s;
}

.intro-text span:nth-child(6) {
    animation-delay: 1.5s;
}

#persistent-lock.unlocking .lock-shackle {
    transform: rotateY(180deg) translateX(-15px);
}

/* 影片過場 */
.video-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease-in-out;
}

#intro-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    /* 開始按鈕點擊前隱藏 */
    transition: opacity 0.5s ease;
}

.fade-in-late {
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 1s ease-out, transform 1s ease-out;
}

.fade-in-late.visible {
    opacity: 1;
    transform: translateY(0);
}

.container {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    box-sizing: border-box;
    border-radius: 0;
}

.parchment {
    background-color: var(--paper-color);
    background-image:
        linear-gradient(rgba(216, 195, 165, 0.4) 1px, transparent 1px),
        linear-gradient(90deg, rgba(216, 195, 165, 0.4) 1px, transparent 1px);
    background-size: 20px 20px;
    box-shadow:
        inset 0 0 80px rgba(139, 69, 19, 0.7),
        inset 0 0 30px rgba(0, 0, 0, 0.6);
    border: none;
}

.parchment::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    box-shadow: inset 0 0 100px rgba(101, 67, 33, 0.3);
    pointer-events: none;
    border-radius: inherit;
}

header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
    z-index: 2;
}

.compass-decoration {
    width: 60px;
    height: 60px;
    border: 3px double var(--gold);
    border-radius: 50%;
    margin: 0 auto 1.5rem auto;
    position: relative;
    box-shadow: 0 0 10px rgba(197, 155, 39, 0.3);
}

.compass-decoration::before,
.compass-decoration::after {
    content: "";
    position: absolute;
    background-color: var(--gold);
}

.compass-decoration::before {
    top: -5px;
    bottom: -5px;
    left: 27px;
    right: 27px;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.compass-decoration::after {
    left: -5px;
    right: -5px;
    top: 27px;
    bottom: 27px;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.compass-decoration {
    width: 60px;
    height: 60px;
    border: 3px double var(--gold);
    border-radius: 50%;
    margin: 0 auto 1.5rem auto;
    position: relative;
    box-shadow: 0 0 10px rgba(197, 155, 39, 0.3);
}

.compass-decoration::before,
.compass-decoration::after {
    content: "";
    position: absolute;
    background-color: var(--gold);
}

.compass-decoration::before {
    top: -5px;
    bottom: -5px;
    left: 27px;
    right: 27px;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

.compass-decoration::after {
    left: -5px;
    right: -5px;
    top: 27px;
    bottom: 27px;
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

h1 {
    color: var(--text-color);
    font-size: 2.2rem;
    margin: 0;
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.5);
    letter-spacing: 2px;
}

.subtitle {
    color: #5d4037;
    font-size: 1rem;
    margin-top: 0.5rem;
    font-style: italic;
}

main {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 2rem;
}

.digit-input {
    width: 50px;
    height: 65px;
    font-size: 2.5rem;
    text-align: center;
    border: 2px solid var(--text-color);
    border-radius: 8px;
    background-color: rgba(255, 255, 255, 0.5);
    color: var(--text-color);
    font-family: inherit;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
}

.digit-input:focus,
.digit-input.active {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(197, 155, 39, 0.6);
    background-color: rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
}

/* 虛擬數字鍵盤 */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px 25px;
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 280px;
}

.num-key {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid var(--text-color);
    color: var(--text-color);
    font-size: 2rem;
    font-family: inherit;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: all 0.1s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.num-key:active {
    transform: scale(0.9);
    background: rgba(197, 155, 39, 0.4);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.action-key {
    font-size: 1rem;
    font-weight: bold;
    background: rgba(62, 39, 35, 0.1);
}

.reveal-btn {
    background: linear-gradient(135deg, #4e342e, var(--text-color));
    color: var(--gold-light);
    border: 2px solid var(--gold);
    padding: 15px 40px;
    font-size: 1.2rem;
    border-radius: 30px;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 2px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
    position: relative;
    overflow: hidden;
}

.reveal-btn::after {
    content: "";
    position: absolute;
    top: 5px;
    right: 5px;
    bottom: 5px;
    left: 5px;
    border: 1px dashed rgba(232, 199, 102, 0.4);
    border-radius: 25px;
    pointer-events: none;
}

.reveal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    background: linear-gradient(135deg, #5d4037, #4e342e);
}

.reveal-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.reveal-btn.secondary {
    background: transparent;
    color: var(--text-color);
    border: 2px solid var(--text-color);
    text-shadow: none;
    padding: 10px 30px;
    font-size: 1rem;
    box-shadow: none;
}

.reveal-btn.secondary::after {
    display: none;
}

.reveal-btn.secondary:hover {
    background-color: rgba(62, 39, 35, 0.1);
    transform: none;
}

.error {
    color: var(--red-wax);
    margin-top: 1.5rem;
    font-weight: bold;
    text-align: center;
    min-height: 24px;
    transition: opacity 0.3s;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}

.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 0.4s ease;
    border-radius: inherit;
}

.modal-content {
    width: 85%;
    padding: 2.5rem 1.5rem;
    text-align: center;
    box-sizing: border-box;
    transform: scale(0.95);
    transition: transform 0.4s ease;
}

.modal:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal h2 {
    color: var(--text-color);
    margin: 0 0 1rem 0;
    font-size: 1.8rem;
}

.divider {
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    margin: 0 auto 1.5rem auto;
    width: 80%;
}

#clue-text {
    font-size: 1.2rem;
    line-height: 1.8;
    color: var(--text-color);
    margin-bottom: 2rem;
    white-space: pre-line;
    font-weight: bold;
}

/* 最終寶藏特效 */
.shake-intense {
    animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both infinite;
}

@keyframes shake {

    10%,
    90% {
        transform: translate3d(-2px, 2px, 0);
    }

    20%,
    80% {
        transform: translate3d(4px, -2px, 0);
    }

    30%,
    50%,
    70% {
        transform: translate3d(-6px, 4px, 0);
    }

    40%,
    60% {
        transform: translate3d(6px, -4px, 0);
    }
}

.golden-burst {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 10px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 150;
    pointer-events: none;
}

.golden-burst.burst-active {
    animation: goldExplosion 2.5s ease-in forwards;
}

@keyframes goldExplosion {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 235, 150, 0.8), 0 0 0 0 rgba(197, 155, 39, 0.8);
        opacity: 0;
    }

    10% {
        opacity: 1;
        box-shadow: 0 0 50px 20px rgba(255, 235, 150, 1), 0 0 100px 50px rgba(197, 155, 39, 1);
    }

    80% {
        opacity: 1;
        box-shadow: 0 0 200px 150px rgba(255, 235, 150, 1), 0 0 500px 300px rgba(197, 155, 39, 1);
        transform: translate(-50%, -50%) scale(1.5);
    }

    100% {
        box-shadow: 0 0 300px 200vw rgba(255, 255, 255, 1), 0 0 500px 300vw rgba(197, 155, 39, 1);
        opacity: 1;
        transform: translate(-50%, -50%) scale(5);
    }
}

/* 最終寶藏專屬樣式 */
.final-prize-modal .modal-content {
    box-shadow: 0 0 50px 10px rgba(197, 155, 39, 0.8), inset 0 0 30px rgba(197, 155, 39, 0.5);
    border: 3px solid var(--gold-light);
    animation: finalGlow 2s infinite alternate;
}

.final-prize-modal h2 {
    color: #8b0000;
    text-shadow: 0 0 10px rgba(139, 0, 0, 0.4);
    font-size: 2.2rem;
}

@keyframes finalGlow {
    from {
        box-shadow: 0 0 30px 5px rgba(197, 155, 39, 0.6), inset 0 0 20px rgba(197, 155, 39, 0.3);
    }

    to {
        box-shadow: 0 0 60px 20px rgba(255, 215, 0, 0.9), inset 0 0 40px rgba(255, 215, 0, 0.6);
    }
}