:root {
    --bg: #F5EDE8;
    --card-bg: rgba(255, 255, 255, 0.72);
    --card-border: rgba(212, 165, 165, 0.25);
    --primary: #B07878;
    --accent: #C08B8B;
    --text: #3D2E2E;
    --text-light: #6B5858;
    --progress-bg: rgba(212, 165, 165, 0.2);
    --progress-fill: #D4A5A5;
    --petal-1: #E8C4C4;
    --petal-2: #D4A5A5;
    --petal-3: #C9B1B1;
    --petal-4: #E0CECE;
    --petal-5: #D9BABA;
    --font-serif: 'Cormorant Garamond', 'Noto Serif SC', serif;
    --font-cn: 'Noto Serif SC', serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-cn);
    background: var(--bg);
}

/* Background Image */
#bgImage {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    transition: opacity 0.6s ease;
    opacity: 0;
}

#bgImage.active {
    opacity: 1;
}

#bgImage::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        180deg,
        rgba(245, 237, 232, 0.3) 0%,
        rgba(245, 237, 232, 0.1) 30%,
        rgba(245, 237, 232, 0.15) 70%,
        rgba(245, 237, 232, 0.35) 100%
    );
}

#petalCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* Music Control */
.music-control {
    position: fixed;
    top: env(safe-area-inset-top, 16px);
    top: 16px;
    right: 16px;
    z-index: 100;
}

.music-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1.5px solid var(--card-border);
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 12px rgba(212, 165, 165, 0.15);
}

.music-btn:active {
    transform: scale(0.92);
}

.music-btn.playing .music-icon {
    animation: musicSpin 2s linear infinite;
}

@keyframes musicSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.music-icon {
    width: 18px;
    height: 18px;
}

/* Card Container */
.card-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    padding: 20px;
}

.card {
    width: 85vw;
    max-width: 400px;
    min-height: 200px;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(6px) saturate(1.2);
    -webkit-backdrop-filter: blur(14px) saturate(1.3);
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 24px;
    box-shadow:
        0 8px 32px rgba(212, 165, 165, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        inset 0 -1px 0 rgba(212, 165, 165, 0.08);
    padding: 36px 28px 24px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.card:active {
    transform: scale(0.985);
    box-shadow:
        0 4px 20px rgba(212, 165, 165, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        inset 0 -1px 0 rgba(212, 165, 165, 0.08);
}

.card-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    min-height: 140px;
    justify-content: center;
}

.card-sequence {
    font-family: var(--font-serif);
    font-size: 14px;
    font-weight: 300;
    color: var(--primary);
    letter-spacing: 2px;
    margin-bottom: 16px;
    opacity: 0;
    transition: opacity 0.4s ease;
    text-transform: uppercase;
}

.card-sequence.visible {
    opacity: 1;
}

.card-text {
    font-family: var(--font-cn);
    font-size: 15.5px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.85;
    text-align: center;
    letter-spacing: 0.5px;
    transition: opacity 0.4s ease;
    max-width: 100%;
    word-break: break-word;
}

.card-text.fade-out {
    opacity: 0;
}

.card-text.fade-in {
    opacity: 1;
}

.card-heart {
    font-size: 22px;
    color: var(--primary);
    margin-top: 20px;
    transition: opacity 0.4s ease, transform 0.4s ease;
    animation: heartBeat 2s ease-in-out infinite;
}

.card-heart.hidden {
    opacity: 0;
    transform: scale(0);
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.15); }
    30% { transform: scale(1); }
    45% { transform: scale(1.08); }
    60% { transform: scale(1); }
}

.card-signature {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 300;
    font-style: italic;
    color: var(--accent);
    margin-top: 16px;
    opacity: 0;
    transition: opacity 0.6s ease;
    letter-spacing: 1px;
}

.card-signature.visible {
    opacity: 1;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 2px;
    background: var(--progress-bg);
    border-radius: 1px;
    margin-top: 24px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--progress-fill);
    border-radius: 1px;
    transition: width 0.5s ease;
}

.progress-text {
    font-family: var(--font-serif);
    font-size: 11px;
    font-weight: 300;
    color: var(--text-light);
    margin-top: 8px;
    letter-spacing: 1px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.progress-text.visible {
    opacity: 1;
}

/* Final state — title above signature */
.card.final .card-signature::before {
    content: '我喜欢一个女孩三十七次，37也是她的幸运数字';
    display: block;
    font-size: 13px;
    font-weight: 400;
    font-style: normal;
    color: var(--primary);
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    line-height: 1.6;
}

/* Loading indicator */
.card.loading .card-inner::after {
    content: '';
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--progress-bg);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: cardSpin 0.6s linear infinite;
}

@keyframes cardSpin {
    to { transform: translateX(-50%) rotate(360deg); }
}

/* Responsive */
@media (max-width: 360px) {
    .card {
        padding: 28px 22px 20px;
    }
    .card-text {
        font-size: 14.5px;
    }
}

@media (min-width: 420px) {
    .card-text {
        font-size: 16px;
    }
}

/* Safe area for notched phones */
@supports (padding-top: env(safe-area-inset-top)) {
    .music-control {
        top: calc(env(safe-area-inset-top) + 12px);
        right: calc(env(safe-area-inset-right) + 12px);
    }
}
