/* 基本樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* 禁止文字選取 */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.is-hidden {
    display: none !important;
}

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #ffeef8 0%, #ffe0f0 50%, #ffd1e8 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
    padding: 10px 0;
}

.home-screen {
    position: relative;
    min-height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    text-align: center;
    overflow: hidden;
}

.home-title,
.home-hint,
.envelopes {
    position: relative;
    z-index: 3;
}

.photo-stage {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.polaroid {
    position: absolute;
    margin: 0;
    padding: 9px 9px 26px;
    width: 132px;
    background: #fffdf8;
    border-radius: 3px;
    box-shadow:
        0 14px 28px rgba(80, 24, 48, 0.22),
        0 1px 0 rgba(255, 255, 255, 0.9) inset;
    opacity: 0.98;
    transform: rotate(var(--tilt, 0deg));
}

.polaroid img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 5;
    height: auto;
    object-fit: cover;
    object-position: center;
    background: #f3e6ec;
}

.pos-l1 { top: 6%; left: 3.5%; --tilt: -6deg; }
.pos-r1 { top: 6%; right: 3.5%; --tilt: 6deg; }
.pos-l2 { top: 38%; left: 2%; --tilt: 5deg; }
.pos-r2 { top: 38%; right: 2%; --tilt: -5deg; }
.pos-l3 { bottom: 7%; left: 4%; --tilt: -4deg; }
.pos-r3 { bottom: 7%; right: 4%; --tilt: 7deg; }

.effect-float {
    animation: photoFloat 6.8s ease-in-out infinite;
}

.effect-sway {
    animation: photoSway 8.2s ease-in-out infinite;
}

@keyframes photoFloat {
    0%, 100% { transform: translateY(0) rotate(var(--tilt, -6deg)); }
    50% { transform: translateY(-8px) rotate(var(--tilt, -6deg)); }
}

@keyframes photoSway {
    0%, 100% { transform: translateY(0) rotate(var(--tilt, 6deg)); }
    50% { transform: translateY(-6px) rotate(var(--tilt, 6deg)); }
}

@keyframes kenBurnsA {
    0% { transform: scale(1) translate(0, 0); }
    100% { transform: scale(1.08) translate(-2%, 2%); }
}

@keyframes kenBurnsB {
    0% { transform: scale(1.06) translate(2%, -2%); }
    100% { transform: scale(1) translate(-1%, 2%); }
}

.memory-photo-frame {
    width: min(260px, 72%);
    margin: 12px auto 0;
    padding: 12px 12px 36px;
    background: #fffdf8;
    border-radius: 3px;
    box-shadow:
        0 16px 32px rgba(80, 24, 48, 0.22),
        0 1px 0 rgba(255, 255, 255, 0.9) inset;
    transform: rotate(-2deg);
}

.memory-photo-crop {
    overflow: hidden;
    width: 100%;
    aspect-ratio: 4 / 5;
    background: #f3e6ec;
}

.memory-photo-frame img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0;
    transition: opacity 0.7s ease;
}

.memory-photo-frame img.is-visible {
    opacity: 1;
}

.memory-photo-frame img.kenburns-a {
    animation: kenBurnsA 10s ease-in-out infinite alternate;
}

.memory-photo-frame img.kenburns-b {
    animation: kenBurnsB 10s ease-in-out infinite alternate;
}

.home-title {
    font-size: 2rem;
    color: #d63384;
    margin-bottom: 8px;
    text-shadow: 2px 2px 4px rgba(214, 51, 132, 0.3);
}

.home-hint {
    color: #d63384;
    opacity: 0.8;
    margin-bottom: 40px;
    font-size: 1rem;
}

.envelopes {
    display: flex;
    gap: 36px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.envelope {
    position: relative;
    width: 180px;
    height: 130px;
    border: none;
    background: #ffb3c6;
    border-radius: 8px 8px 12px 12px;
    box-shadow: 0 12px 28px rgba(214, 51, 132, 0.28);
    cursor: pointer;
    overflow: hidden;
    animation: envelopeFloat 5.5s ease-in-out infinite;
}

.envelope-alt {
    background: #ff91a4;
    animation-duration: 6.4s;
    animation-delay: -2.4s;
}

.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 58px;
    background: linear-gradient(180deg, #ffd1e8 0%, #ff9bb5 100%);
    clip-path: polygon(0 0, 50% 78%, 100% 0);
}

.envelope-year {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 22px;
    font-size: 1.8rem;
    font-weight: bold;
    color: #fff;
    letter-spacing: 2px;
    text-shadow: 0 2px 6px rgba(176, 42, 91, 0.45);
}

.envelope.opening {
    animation: envelopeOpen 0.45s ease-out forwards;
}

@keyframes envelopeFloat {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-14px) rotate(2.5deg); }
}

@keyframes envelopeOpen {
    0% { transform: scale(1) rotate(-2deg); }
    100% { transform: scale(1.08) rotate(0deg); }
}

.back-home-btn {
    align-self: flex-start;
    background: transparent;
    border: 1px solid rgba(214, 51, 132, 0.35);
    color: #d63384;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 4px;
}

.cover-subheading {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.container {
    text-align: center;
    padding: 15px;
    max-width: 500px;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

/* 標題樣式 */
.title {
    font-size: 2rem;
    color: #d63384;
    margin-bottom: 1.5rem;
    margin-top: 1rem;
    text-shadow: 2px 2px 4px rgba(214, 51, 132, 0.3);
    animation: titleBounce 2s ease-in-out infinite alternate;
}

@keyframes titleBounce {
    0% { transform: translateY(0px); }
    100% { transform: translateY(-10px); }
}

/* 多頁賀卡樣式 */
.card-book-container {
    margin: 1rem auto;
    max-width: 100%;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-book {
    position: relative;
    width: 100%;
    height: 500px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(214, 51, 132, 0.3);
    background: #fff;
    flex: 1;
    min-height: 500px;
}

.card-page {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ff9bb5 0%, #ff7a9a 100%);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px 25px;
    box-sizing: border-box;
    transform: translateX(100%);
    transition: transform 0.6s cubic-bezier(0.4, 0.0, 0.2, 1);
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
}

.card-page.active {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

.card-page.prev {
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
}

.page-content {
    text-align: center;
    color: white;
    width: 100%;
}

/* 封面樣式 */
.cover-content h2 {
    font-size: 5rem;
    margin-bottom: 25px;
    animation: bounce 2s ease-in-out infinite;
}

.cover-content p {
    font-size: 1.4rem;
    font-weight: bold;
    margin-bottom: 20px;
}

.heart {
    font-size: 3rem;
    animation: heartBeat 1.5s ease-in-out infinite;
    margin: 25px 0;
}

.tap-hint {
    font-size: 1rem;
    opacity: 0.8;
    animation: pulse 2s ease-in-out infinite;
    margin-top: 20px;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-10px); }
    60% { transform: translateY(-5px); }
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 0.4; }
}

/* 內頁樣式 */
.page-content h3 {
    font-size: 2.2rem;
    margin-bottom: 30px;
    color: #fff;
}

.page-content p {
    font-size: 1.3rem;
    line-height: 1.8;
    margin-bottom: 15px;
}

.page-decoration {
    font-size: 2.5rem;
    margin: 30px 0;
    animation: heartBeat 1.5s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.2) rotate(180deg); }
}

.signature {
    margin-top: 30px;
    font-style: italic;
    font-size: 1.2rem;
    opacity: 0.9;
}

/* 蛋糕頁面特殊樣式 */
.cake-page {
    background: linear-gradient(135deg, #ffb3c6 0%, #ff91a4 100%) !important;
    padding: 20px 25px !important;
}

.cake-page h3 {
    font-size: 1.8rem;
    margin-bottom: 20px;
}

/* 頁面指示器 */
.page-indicators {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
}

.indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(214, 51, 132, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.indicator.active {
    background: #d63384;
    transform: scale(1.2);
}

.indicator:hover {
    background: rgba(214, 51, 132, 0.6);
}

.cake-wrapper {
    display: inline-block;
    margin: 15px 0;
}

.birthday-cake {
    width: 250px;
    height: 200px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.birthday-cake:hover {
    transform: scale(1.05);
}

/* 蠟燭火焰動畫 */
.flame, .flame-inner {
    animation: flicker 0.5s ease-in-out infinite alternate;
    transform-origin: center bottom;
}

@keyframes flicker {
    0% { transform: scale(1) rotate(-1deg); }
    100% { transform: scale(1.1) rotate(1deg); }
}

.candle.blown-out .flame,
.candle.blown-out .flame-inner {
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* 蛋糕說明 */
.cake-instructions {
    margin: 10px 0;
}

.cake-instructions p {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: white;
}

/* 簡化的說明文字 */
.instruction {
    font-size: 0.9rem;
    color: white;
    margin-bottom: 10px;
}

.mobile-permission-hint,
.volume-indicator,
.blow-progress {
    display: none;
}

.mobile-permission-hint {
    margin: 10px 0;
    padding: 8px 12px;
    background: rgba(255, 193, 7, 0.2);
    border: 1px solid rgba(255, 193, 7, 0.5);
    border-radius: 15px;
    animation: permissionPulse 2s ease-in-out infinite;
}

.mobile-permission-hint p {
    font-size: 0.8rem;
    color: #FFC107;
    margin: 0;
    text-align: center;
}

@keyframes permissionPulse {
    0%, 100% {
        background: rgba(255, 193, 7, 0.2);
        border-color: rgba(255, 193, 7, 0.5);
    }
    50% {
        background: rgba(255, 193, 7, 0.4);
        border-color: rgba(255, 193, 7, 0.8);
    }
}

.mic-button {
    background: linear-gradient(135deg, #ff7a9a 0%, #ff5577 100%);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(255, 122, 154, 0.4);
}

.mic-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(255, 122, 154, 0.6);
}

.mic-button:active {
    transform: translateY(0);
}

/* 音量指示器 */
.volume-indicator {
    margin-top: 10px;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.volume-label {
    font-size: 0.8rem;
    color: white;
}

.volume-bar {
    width: 100px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.volume-level {
    height: 100%;
    background: linear-gradient(90deg, #4CAF50, #FFC107, #FF5722);
    width: 0%;
    transition: width 0.1s ease;
    border-radius: 4px;
}

/* 吹氣進度條 */
.blow-progress {
    margin-top: 10px;
    align-items: center;
    gap: 10px;
    justify-content: center;
}

.progress-label {
    font-size: 0.8rem;
    color: white;
}

.progress-bar {
    width: 100px;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    overflow: hidden;
}

.progress-level {
    height: 100%;
    background: linear-gradient(90deg, #FF6B35, #F7931E, #FFD700);
    width: 0%;
    transition: width 0.2s ease;
    border-radius: 4px;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* 控制按鈕 */
.controls {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    position: relative;
    z-index: 10;
    touch-action: manipulation; /* 防止滑動手勢干擾 */
}

.control-btn {
    background: linear-gradient(135deg, #ff91a4 0%, #ff7a9a 100%);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 3px 10px rgba(255, 145, 164, 0.4);
    position: relative;
    z-index: 10;
    min-height: 44px; /* 確保觸摸目標足夠大 */
    min-width: 120px;
    touch-action: manipulation; /* 優化觸摸響應 */
}

.control-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(255, 145, 164, 0.6);
}

/* 彩帶動畫 */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #ff6b9d;
    animation: confettiFall 3s linear forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
        opacity: 0;
    }
}

/* 全屏烟火效果 */
.fireworks-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.8);
    opacity: 0;
    transition: opacity 0.5s ease;
    will-change: opacity;
    transform: translateZ(0); /* 啟用硬件加速 */
}

.fireworks-container.active {
    opacity: 1;
}

.photo-rain-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1002;
    overflow: hidden;
}

.photo-rain-drop {
    position: absolute;
    top: -90px;
    object-fit: cover;
    border: 3px solid #fff;
    border-bottom-width: 8px;
    border-radius: 2px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
    animation: photoRainFall linear forwards;
    will-change: transform, opacity;
    transform: translateZ(0);
}

@keyframes photoRainFall {
    0% {
        transform: translate3d(0, 0, 0) rotate(var(--rot-start));
        opacity: 0;
    }
    8% {
        opacity: 1;
    }
    100% {
        transform: translate3d(var(--dx), 115vh, 0) rotate(var(--rot-end));
        opacity: 0.75;
    }
}

.firework {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    will-change: transform;
    transform: translateZ(0);
}

.firework-trail {
    position: absolute;
    width: 2px;
    height: 20px;
    border-radius: 1px;
    animation: fireworkTrail 1s ease-out forwards;
    will-change: transform, opacity;
    transform: translateZ(0);
}

.firework-explosion {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: fireworkExplosion 1.5s ease-out forwards;
    will-change: transform, opacity;
    transform: translateZ(0);
}

.firework-particle {
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    animation: fireworkParticle 2s ease-out forwards;
    will-change: transform, opacity;
    transform: translateZ(0);
}

@keyframes fireworkTrail {
    0% {
        transform: translate3d(0, 100vh, 0) scale3d(1, 1, 1);
        opacity: 1;
    }
    100% {
        transform: translate3d(0, 0, 0) scale3d(0.5, 0.5, 1);
        opacity: 0.8;
    }
}

@keyframes fireworkExplosion {
    0% {
        transform: scale3d(0, 0, 1);
        opacity: 1;
    }
    50% {
        transform: scale3d(8, 8, 1);
        opacity: 0.8;
    }
    100% {
        transform: scale3d(15, 15, 1);
        opacity: 0;
    }
}

@keyframes fireworkParticle {
    0% {
        transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
        opacity: 1;
    }
    100% {
        transform: translate3d(var(--dx), var(--dy), 0) scale3d(0, 0, 1);
        opacity: 0;
    }
}

/* 烟火闪烁效果 */
@keyframes fireworkSparkle {
    0%, 100% {
        opacity: 0;
        transform: scale3d(0, 0, 1);
    }
    50% {
        opacity: 1;
        transform: scale3d(1, 1, 1);
    }
}

.firework-sparkle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    animation: fireworkSparkle 0.5s ease-in-out infinite;
    will-change: transform, opacity;
    transform: translateZ(0);
}

@media (max-width: 768px) {
    .title {
        font-size: 1.8rem;
    }

    .card-book {
        width: 100%;
        height: auto;
        min-height: 60vh;
    }

    .cover-content h2 {
        font-size: 3rem;
    }

    .page-content h3 {
        font-size: 1.5rem;
    }

    .page-content p {
        font-size: 1rem;
    }

    .birthday-cake {
        width: 180px;
        height: 140px;
    }

    .envelopes {
        flex-direction: column;
        gap: 28px;
    }

    .polaroid {
        width: 112px;
        padding: 7px 7px 20px;
    }

    .polaroid img {
        height: auto;
    }

    .pos-l2,
    .pos-r2 {
        display: none;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    .title,
    .home-title {
        font-size: 1.5rem;
    }

    .card-book {
        width: 100%;
        min-height: 60vh;
    }

    .cover-content h2 {
        font-size: 2.5rem;
    }

    .page-content h3 {
        font-size: 1.3rem;
    }

    .page-content p {
        font-size: 0.9rem;
    }

    .birthday-cake {
        width: 160px;
        height: 120px;
    }

    .controls {
        flex-direction: column;
        gap: 8px;
    }

    .control-btn, .mic-button {
        width: 150px;
        margin: 0 auto;
    }
}
