/* ===== Design Tokens & Biến hệ thống ===== */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);

    --font-sans: 'Quicksand', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-serif: 'Lora', Georgia, Cambria, "Times New Roman", serif;

    --bg-center: #fff9fb;
    --bg-mid: #fff0f5;
    --bg-edge: #fde2ec;

    --rose-500: #e35d88;
    --rose-600: #c94470;
    --rose-700: #9e3558;
    --ink-body: #5e2b3e;
    --ink-muted: rgba(142, 62, 92, 0.62);
    --border-soft: rgba(236, 176, 198, 0.62);
    --border-hairline: rgba(232, 174, 196, 0.42);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: manipulation;
    font-family: var(--font-sans);
    color: var(--ink-body);
    background: radial-gradient(circle at 50% 44%, var(--bg-center) 0%, var(--bg-mid) 54%, var(--bg-edge) 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button:focus-visible {
    outline: 2px solid var(--rose-500);
    outline-offset: 3px;
}

/* ===== Khung Canvas 3D ===== */
#canvas-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    cursor: grab;
    touch-action: none;
}

canvas:active {
    cursor: grabbing;
}

/* ===== Bề mặt kính mờ tinh tế (Frosted Pearl Glass) ===== */
.glass-panel {
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-soft);
    box-shadow:
        0 10px 28px -6px rgba(188, 92, 128, 0.16),
        0 2px 6px rgba(188, 92, 128, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transform: translateZ(0);
}

/* ===== Màn hình mở đầu (Intro Overlay) ===== */
.intro-screen {
    background: radial-gradient(circle at 50% 44%, var(--bg-center) 0%, var(--bg-mid) 54%, var(--bg-edge) 100%);
    will-change: transform, opacity;
    transform: translateZ(0);
}

.intro-date-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.32rem 0.95rem;
    margin-bottom: 1.15rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid rgba(236, 180, 200, 0.52);
    box-shadow: 0 4px 14px rgba(200, 110, 142, 0.08);
    font-family: var(--font-serif);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--rose-700);
}

.intro-date-dot {
    width: 4px;
    height: 4px;
    border-radius: 9999px;
    background: #eb85a6;
}

/* Khung ảnh thủ công Polaroid & Washi Tape chân thực */
#cat-card {
    opacity: 0;
    transition: opacity 0.32s ease-out, transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

#cat-card.is-loaded {
    opacity: 1;
}

.polaroid-outer {
    position: relative;
    padding: 0.75rem;
    border-radius: 2rem;
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.96);
    box-shadow:
        0 24px 52px -12px rgba(196, 102, 138, 0.22),
        0 6px 16px -4px rgba(196, 102, 138, 0.09);
}

.polaroid-inner {
    padding: 0.65rem;
    border-radius: 1.5rem;
    border: 1px dashed rgba(238, 168, 194, 0.72);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.82) 0%, rgba(255, 244, 248, 0.58) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (min-width: 640px) {
    .polaroid-outer {
        padding: 1rem;
        border-radius: 2.5rem;
    }

    .polaroid-inner {
        padding: 0.9rem;
        border-radius: 1.95rem;
    }
}

/* Băng keo giấy Washi Tape mờ viền răng cưa thủ công */
.washi-tape {
    position: absolute;
    top: -0.72rem;
    left: 50%;
    transform: translateX(-50%) rotate(-1.6deg);
    width: 6.4rem;
    height: 1.45rem;
    background: linear-gradient(90deg, rgba(248, 184, 206, 0.62), rgba(252, 202, 219, 0.72), rgba(248, 184, 206, 0.62));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-top: 1px solid rgba(255, 255, 255, 0.55);
    border-bottom: 1px solid rgba(232, 156, 182, 0.45);
    box-shadow: 0 3px 8px rgba(190, 96, 130, 0.10);
    clip-path: polygon(
        2% 0%, 98% 0%, 100% 18%, 97% 36%, 100% 54%, 97% 72%, 100% 90%, 98% 100%,
        2% 100%, 0% 82%, 3% 64%, 0% 46%, 3% 28%, 0% 10%
    );
    z-index: 10;
    pointer-events: none;
}

@media (min-width: 640px) {
    .washi-tape {
        top: -0.85rem;
        width: 7.8rem;
        height: 1.7rem;
    }
}

/* Nút bấm chính ấm áp, sang trọng (không chói gắt) */
.btn-primary-rose {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border-radius: 9999px;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, #e5638b 0%, #ee7a9c 50%, #df5680 100%);
    background-size: 180% auto;
    border: 1px solid rgba(255, 224, 235, 0.65);
    box-shadow:
        0 10px 24px -4px rgba(218, 86, 128, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.42);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.28s ease,
        background-position 0.35s ease,
        opacity 0.28s ease;
    cursor: pointer;
}

.btn-primary-rose:hover {
    background-position: right center;
    transform: translateY(-2px);
    box-shadow:
        0 14px 28px -4px rgba(218, 86, 128, 0.40),
        inset 0 1px 0 rgba(255, 255, 255, 0.52);
}

.btn-primary-rose:active {
    transform: translateY(0) scale(0.96);
}

.intro-subtitle {
    margin-top: 0.7rem;
    font-size: 0.84rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink-muted);
    transition: color 0.25s ease;
    cursor: pointer;
}

.intro-subtitle:hover {
    color: var(--rose-700);
}

@media (min-width: 640px) {
    .intro-subtitle {
        margin-top: 0.82rem;
        font-size: 0.95rem;
    }
}

/* ===== Nút Nhạc nền góc trên phải ===== */
#btn-music {
    top: max(1.15rem, calc(var(--sat) + 0.6rem));
    right: max(1.15rem, calc(var(--sar) + 0.6rem));
    will-change: transform, opacity;
}

.music-heart-svg {
    width: 1.35rem;
    height: 1.35rem;
}

@media (min-width: 640px) {
    .music-heart-svg {
        width: 1.5rem;
        height: 1.5rem;
    }
}

.hud-icon {
    width: 1.05rem;
    height: 1.05rem;
    flex-shrink: 0;
}

.card-bear-svg {
    width: 6.25rem;
    height: 6.25rem;
}

@media (min-width: 640px) {
    .card-bear-svg {
        width: 7.25rem;
        height: 7.25rem;
    }
}

/* ===== Thanh HUD dưới bó hoa: Kính mờ thanh lịch, tôn vinh bó hoa 3D ===== */
.bouquet-hud {
    position: fixed;
    left: 50%;
    bottom: max(2.1rem, calc(var(--sab) + 1.4rem));
    transform: translate3d(-50%, 0, 0);
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.45rem;
    max-width: 92vw;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform, opacity;
}

.bouquet-hud.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate3d(-50%, 8px, 0);
}

.bouquet-hud.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translate3d(-50%, 0, 0);
}

.bouquet-hud-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.62rem 1.45rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(235, 168, 192, 0.72);
    color: var(--rose-700);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.015em;
    box-shadow:
        0 10px 26px -4px rgba(186, 88, 124, 0.20),
        0 2px 6px rgba(186, 88, 124, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.95);
    cursor: pointer;
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        background-color 0.25s ease,
        border-color 0.25s ease,
        box-shadow 0.28s ease;
    animation: pillFloatGentle 3.2s ease-in-out infinite;
}

@media (min-width: 640px) {
    .bouquet-hud-pill {
        padding: 0.72rem 1.75rem;
        font-size: 0.98rem;
    }
}

.bouquet-hud-pill:hover {
    animation-play-state: paused;
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(226, 134, 168, 0.85);
    transform: translate3d(0, -3px, 0);
    box-shadow:
        0 14px 30px -4px rgba(186, 88, 124, 0.26),
        inset 0 1px 0 #ffffff;
}

.bouquet-hud-pill:active {
    transform: translate3d(0, 0, 0) scale(0.96);
}

.gesture-caption {
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: rgba(142, 62, 92, 0.52);
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

@media (max-width: 1024px) and (orientation: portrait) {
    .bouquet-hud {
        bottom: max(4.2rem, calc(var(--sab) + 3.5rem));
    }
}

@media (max-width: 1024px) and (orientation: landscape) {
    .bouquet-hud {
        bottom: max(0.85rem, calc(var(--sab) + 0.5rem));
        gap: 0.25rem;
    }

    .gesture-caption {
        display: none;
    }
}

/* ===== Thiệp chúc mừng văn phòng phẩm cao cấp (Fine Stationery Modal) ===== */
#card-modal {
    padding: max(1rem, var(--sat)) max(1rem, var(--sar)) max(1rem, var(--sab)) max(1rem, var(--sal));
    background: rgba(68, 18, 38, 0.22);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overscroll-behavior: contain;
    will-change: opacity;
    contain: paint layout;
}

.stationery-card {
    position: relative;
    width: min(92vw, 28.5rem);
    max-height: 88dvh;
    overflow-y: auto;
    border-radius: 1.85rem;
    padding: 1.5rem 1.35rem 1.45rem;
    background: linear-gradient(180deg, rgba(255, 254, 254, 0.97) 0%, rgba(255, 247, 250, 0.96) 100%);
    border: 1px solid rgba(236, 182, 202, 0.78);
    box-shadow:
        0 28px 64px -12px rgba(132, 46, 78, 0.28),
        0 6px 20px -4px rgba(132, 46, 78, 0.10),
        inset 0 1px 0 #ffffff;
    text-align: center;
    will-change: transform, opacity;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    transform: translateZ(0);
}

/* Khung viền mảnh lồng bên trong tạo cảm giác thiệp giấy mỹ thuật in nổi */
.stationery-card::before {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 1.35rem;
    border: 1px solid var(--border-hairline);
    pointer-events: none;
}

@media (min-width: 640px) {
    .stationery-card {
        padding: 2rem 2.15rem 1.85rem;
        border-radius: 2.1rem;
    }

    .stationery-card::before {
        inset: 11px;
        border-radius: 1.55rem;
    }
}

.stationery-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    margin: 0.15rem auto 0.65rem;
    font-family: var(--font-serif);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    color: rgba(186, 86, 122, 0.72);
}

.stationery-divider::before,
.stationery-divider::after {
    content: "";
    width: 2.1rem;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(226, 148, 176, 0.65), transparent);
}

.card-greeting-title {
    font-family: var(--font-serif);
    font-size: 1.38rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--rose-600);
    margin-bottom: 0.65rem;
    letter-spacing: 0.01em;
}

.card-message-body {
    font-family: var(--font-sans);
    font-size: 0.94rem;
    font-weight: 600;
    line-height: 1.72;
    color: var(--ink-body);
    padding: 0 0.25rem;
    white-space: pre-line;
}

@media (min-width: 640px) {
    .card-greeting-title {
        font-size: 1.65rem;
        margin-bottom: 0.8rem;
    }

    .card-message-body {
        font-size: 1.03rem;
        padding: 0 0.5rem;
    }
}

/* Kỹ thuật Ghost-Sizer CSS Grid: khóa cố định chiều cao thiệp ngay từ đầu, chống nhảy khung (Zero CLS) khi gõ chữ */
.typewriter-stack {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
}

.typewriter-sizer,
.typewriter-live {
    grid-area: 1 / 1;
}

.typewriter-sizer {
    visibility: hidden;
    pointer-events: none;
    white-space: pre-line;
}

.typewriter-live {
    white-space: pre-line;
}

.typewriter-caret {
    display: inline-block;
    width: 2px;
    height: 1.05em;
    background: var(--rose-500);
    border-radius: 9999px;
    margin-left: 3px;
    vertical-align: -0.14em;
    animation: caretBlink 0.9s ease-in-out infinite;
}

/* Vùng chân thiệp giữ kích thước ổn định khi chuyển từ gợi ý sang nút Đóng */
.card-footer-slot {
    position: relative;
    margin-top: 1.25rem;
    min-height: 2.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-skip-caption {
    position: absolute;
    font-size: 0.76rem;
    font-weight: 600;
    color: rgba(160, 82, 112, 0.55);
    letter-spacing: 0.02em;
    transition: opacity 0.25s ease;
    pointer-events: none;
}

/* Thanh cuộn mảnh cho thiệp trên màn hình nhỏ */
.stationery-card::-webkit-scrollbar {
    width: 4px;
}

.stationery-card::-webkit-scrollbar-track {
    background: transparent;
}

.stationery-card::-webkit-scrollbar-thumb {
    background: rgba(232, 132, 168, 0.35);
    border-radius: 9999px;
}

/* ===== Keyframes hoạt ảnh mượt trên GPU ===== */
@keyframes floatAnimation {
    0%,
    100% {
        transform: translate3d(0, 0, 0) rotate(0deg);
    }

    50% {
        transform: translate3d(0, -7px, 0) rotate(0.8deg);
    }
}

.floating-cat {
    animation: floatAnimation 3.6s ease-in-out infinite;
    will-change: transform;
}

@keyframes pillFloatGentle {
    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }

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

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

    16% {
        transform: scale(1.16);
    }

    34% {
        transform: scale(1.0);
    }

    50% {
        transform: scale(1.14);
    }
}

.animate-heartbeat {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    animation: heartBeat 1.8s ease-in-out infinite;
    transform-origin: center center;
    will-change: transform;
}

@keyframes bearFloat {
    0%,
    100% {
        transform: translate3d(0, 0, 0) rotate(0deg);
    }

    50% {
        transform: translate3d(0, -3.5px, 0) rotate(1deg);
    }
}

.floating-bear {
    animation: bearFloat 3.4s ease-in-out infinite;
    will-change: transform;
}

@keyframes caretBlink {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.2;
    }
}

/* ===== Hạt tim & ánh sao nhỏ tinh tế khi chạm màn hình ===== */
@keyframes heartBurstFloat {
    0% {
        opacity: 0.92;
        transform: translate(-50%, -50%) translate3d(0, 0, 0) scale(0.35) rotate(0deg);
    }

    45% {
        opacity: 0.88;
        transform: translate(-50%, -50%) translate3d(var(--tx), var(--ty), 0) scale(var(--scale, 1.0)) rotate(var(--rot, 12deg));
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) translate3d(calc(var(--tx) * 1.3), calc(var(--ty) - 30px), 0) scale(0.45) rotate(calc(var(--rot, 12deg) * 1.5));
    }
}

.heart-burst-particle {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    contain: strict;
    will-change: transform, opacity;
    animation: heartBurstFloat var(--duration, 820ms) cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}

/* Tôn trọng cài đặt giảm chuyển động của hệ điều hành */
@media (prefers-reduced-motion: reduce) {
    .floating-cat,
    .floating-bear,
    .bouquet-hud-pill,
    .animate-heartbeat {
        animation: none !important;
    }
}
