/* ===== He thong Design Tokens: Che do Nang Som (Day) & Dem Sao (Night) ===== */
: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-display: 'Cormorant Garamond', 'Lora', Georgia, serif;
    --font-serif: 'Lora', Georgia, serif;
    --font-sans: 'Quicksand', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

    /* Bang mau Nang Som (Mac dinh) */
    --glass-bg: rgba(255, 255, 255, 0.80);
    --glass-bg-strong: rgba(255, 252, 253, 0.95);
    --glass-border: rgba(235, 178, 198, 0.64);
    --glass-shadow: 0 12px 32px -6px rgba(176, 82, 118, 0.16), 0 2px 8px rgba(176, 82, 118, 0.06);
    --glass-inset: inset 0 1px 0 rgba(255, 255, 255, 0.92);

    --text-primary: #522335;
    --text-secondary: rgba(112, 52, 76, 0.78);
    --text-muted: rgba(136, 68, 94, 0.56);
    --accent-rose: #d95b84;
    --accent-deep: #ab3960;
    --accent-soft-bg: rgba(235, 116, 156, 0.14);

    --card-surface: linear-gradient(180deg, rgba(255, 254, 254, 0.97) 0%, rgba(255, 247, 250, 0.96) 100%);
    --card-border: rgba(234, 180, 200, 0.76);
    --card-hairline: rgba(226, 166, 188, 0.38);
    --stage-surface: radial-gradient(circle at 50% 42%, #fff8fb 0%, #f9e0ea 100%);
    --modal-veil: rgba(64, 20, 38, 0.20);
}

html[data-theme="night"] {
    --glass-bg: rgba(34, 21, 42, 0.76);
    --glass-bg-strong: rgba(38, 23, 46, 0.94);
    --glass-border: rgba(248, 196, 218, 0.24);
    --glass-shadow: 0 14px 36px -6px rgba(8, 3, 14, 0.54), 0 2px 10px rgba(0, 0, 0, 0.30);
    --glass-inset: inset 0 1px 0 rgba(255, 232, 242, 0.14);

    --text-primary: #fbf0f5;
    --text-secondary: rgba(246, 222, 234, 0.84);
    --text-muted: rgba(232, 198, 215, 0.56);
    --accent-rose: #f493b4;
    --accent-deep: #ffc2d6;
    --accent-soft-bg: rgba(244, 147, 180, 0.18);

    --card-surface: linear-gradient(180deg, rgba(42, 26, 50, 0.96) 0%, rgba(30, 18, 38, 0.96) 100%);
    --card-border: rgba(246, 190, 214, 0.28);
    --card-hairline: rgba(246, 190, 214, 0.16);
    --stage-surface: radial-gradient(circle at 50% 42%, #3a2346 0%, #21132b 100%);
    --modal-veil: rgba(12, 6, 18, 0.48);
}

*,
*::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(--text-primary);
    background-color: #fffaf8;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

button {
    font-family: inherit;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
}

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

.icon-xs {
    width: 0.88rem;
    height: 0.88rem;
    flex-shrink: 0;
}

.icon-sm {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

/* ===== Bau troi chuyen canh GPU 60fps ===== */
.sky-backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.sky-layer-day {
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 44%, #fffbf9 0%, #fff0f5 54%, #fadde9 100%);
}

.sky-layer-night {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 42%, rgba(98, 52, 92, 0.46) 0%, rgba(42, 23, 52, 0.88) 52%, #130c1c 100%);
    opacity: 0;
    transition: opacity 0.95s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: opacity;
}

.sky-layer-night::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(1.2px 1.2px at 14% 18%, rgba(255, 248, 235, 0.85) 50%, transparent 100%),
        radial-gradient(1.5px 1.5px at 28% 11%, rgba(255, 224, 238, 0.75) 50%, transparent 100%),
        radial-gradient(1px 1px at 44% 22%, rgba(255, 255, 255, 0.7) 50%, transparent 100%),
        radial-gradient(1.6px 1.6px at 67% 14%, rgba(255, 240, 210, 0.85) 50%, transparent 100%),
        radial-gradient(1.2px 1.2px at 83% 20%, rgba(255, 230, 242, 0.8) 50%, transparent 100%),
        radial-gradient(1px 1px at 91% 36%, rgba(255, 255, 255, 0.65) 50%, transparent 100%),
        radial-gradient(1.3px 1.3px at 9% 42%, rgba(255, 238, 215, 0.7) 50%, transparent 100%),
        radial-gradient(1.1px 1.1px at 76% 46%, rgba(255, 255, 255, 0.6) 50%, transparent 100%),
        radial-gradient(1.4px 1.4px at 19% 72%, rgba(255, 225, 238, 0.65) 50%, transparent 100%),
        radial-gradient(1.2px 1.2px at 86% 74%, rgba(255, 244, 218, 0.7) 50%, transparent 100%);
}

html[data-theme="night"] .sky-layer-night {
    opacity: 1;
}

/* ===== Khong gian Canvas 3D ===== */
#canvas-container {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    overflow: hidden;
}

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

canvas:active {
    cursor: grabbing;
}

/* ===== Man hinh Phong Thu Niem Sap Mo Dau ===== */
.prelude-overlay {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: radial-gradient(circle at 50% 45%, #fffcf9 0%, #fdf1f5 56%, #f8dfea 100%);
    transition: opacity 0.85s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.85s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform, opacity;
}

.prelude-overlay.is-opened {
    opacity: 0;
    transform: scale(1.04) translateY(-10px);
    pointer-events: none;
}

.envelope-card {
    position: relative;
    width: min(90vw, 25.5rem);
    padding: 2.55rem 1.75rem 2.15rem;
    border-radius: 1.65rem;
    background: linear-gradient(165deg, #fffefb 0%, #fff8fa 55%, #fdf0f4 100%);
    border: 1px solid rgba(226, 176, 192, 0.68);
    box-shadow:
        0 28px 60px -15px rgba(164, 78, 108, 0.22),
        0 6px 18px -4px rgba(164, 78, 108, 0.08),
        inset 0 1px 0 #ffffff;
    text-align: center;
    cursor: pointer;
    transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.38s ease;
    animation: envelopeFloat 4s ease-in-out infinite;
}

.envelope-card::before {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 1.2rem;
    border: 1px solid rgba(222, 168, 186, 0.36);
    pointer-events: none;
}

.envelope-card:hover {
    animation-play-state: paused;
    transform: translateY(-4px);
    box-shadow:
        0 34px 68px -14px rgba(164, 78, 108, 0.28),
        0 8px 22px -4px rgba(164, 78, 108, 0.10),
        inset 0 1px 0 #ffffff;
}

.envelope-flap-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 7.5rem;
    pointer-events: none;
    opacity: 0.55;
}

.prelude-tag {
    position: relative;
    font-family: var(--font-serif);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(158, 76, 106, 0.74);
    margin-bottom: 0.55rem;
}

.prelude-recipient {
    position: relative;
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 8vw, 3.15rem);
    font-weight: 600;
    font-style: italic;
    line-height: 1.12;
    color: #9e3358;
    letter-spacing: 0.015em;
    margin-bottom: 0.35rem;
}

.prelude-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    margin: 0.55rem auto 1.45rem;
    color: rgba(202, 122, 148, 0.78);
}

.prelude-ornament::before,
.prelude-ornament::after {
    content: "";
    width: 2.6rem;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(214, 144, 168, 0.68), transparent);
}

.ornament-diamond-svg {
    width: 0.85rem;
    height: 0.85rem;
}

/* Con dau sap hoa Tulip dap noi */
.wax-seal-btn {
    position: relative;
    width: 4.65rem;
    height: 4.65rem;
    margin: 0 auto 1.25rem;
    border-radius: 52% 48% 50% 50% / 49% 52% 48% 51%;
    background: radial-gradient(circle at 35% 30%, #e57393 0%, #c8466c 58%, #9c2b4d 100%);
    box-shadow:
        0 10px 22px -4px rgba(156, 43, 77, 0.42),
        0 2px 5px rgba(120, 28, 56, 0.25),
        inset 0 2px 4px rgba(255, 215, 226, 0.48),
        inset 0 -3px 6px rgba(92, 18, 40, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff3e6;
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
        box-shadow 0.32s ease;
}

.wax-seal-btn::before {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 1.2px solid rgba(255, 232, 214, 0.48);
    box-shadow: inset 0 1px 3px rgba(92, 18, 40, 0.38);
}

.wax-seal-btn:hover {
    transform: scale(1.07) rotate(-2deg);
    box-shadow:
        0 14px 28px -4px rgba(156, 43, 77, 0.50),
        inset 0 2px 5px rgba(255, 225, 234, 0.58),
        inset 0 -3px 6px rgba(92, 18, 40, 0.45);
}

.wax-seal-btn:active {
    transform: scale(0.95);
}

.wax-seal-icon {
    width: 1.85rem;
    height: 1.85rem;
    filter: drop-shadow(0 1px 2px rgba(92, 18, 40, 0.35));
}

.prelude-hint {
    font-size: 0.84rem;
    font-weight: 600;
    color: rgba(138, 66, 92, 0.68);
    letter-spacing: 0.015em;
}

/* ===== Thanh HUD phia tren (Dia than Vinyl 11 bai & Nut Chuyen Nang/Dem) ===== */
.top-bar {
    position: fixed;
    top: max(0.8rem, calc(var(--sat) + 0.45rem));
    left: max(0.8rem, calc(var(--sal) + 0.45rem));
    right: max(0.8rem, calc(var(--sar) + 0.45rem));
    z-index: 48;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.top-bar.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.glass-pill {
    pointer-events: auto;
    background: var(--glass-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), var(--glass-inset);
    border-radius: 9999px;
    transition: background-color 0.4s ease, border-color 0.4s ease, color 0.4s ease, transform 0.25s ease;
}

.vinyl-pill-wrap {
    position: relative;
    pointer-events: auto;
    max-width: min(64vw, 19.5rem);
}

.vinyl-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.46rem 0.3rem 0.34rem;
    max-width: 100%;
}

.vinyl-disc-btn {
    position: relative;
    width: 2.15rem;
    height: 2.15rem;
    flex-shrink: 0;
    border-radius: 50%;
    background:
        radial-gradient(circle at 50% 50%, #ffffff 0 9%, #e67e9e 10% 29%, #1f1722 30% 45%, #332738 46% 48%, #1d1520 49% 64%, #312536 65% 67%, #18111b 68% 100%);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.22);
    animation: vinylSpin 6.5s linear infinite;
    animation-play-state: paused;
}

.vinyl-disc-btn.is-spinning {
    animation-play-state: running;
}

.vinyl-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    text-align: left;
    padding: 0.05rem 0.15rem;
}

.vinyl-title-row {
    display: flex;
    align-items: center;
    gap: 0.34rem;
    min-width: 0;
}

.vinyl-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vinyl-chevron {
    width: 0.82rem;
    height: 0.82rem;
    flex-shrink: 0;
    color: var(--text-muted);
    transition: transform 0.28s ease;
}

.vinyl-pill-wrap.is-open .vinyl-chevron {
    transform: rotate(180deg);
}

.vinyl-status {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eq-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    height: 10px;
    flex-shrink: 0;
}

.eq-bar {
    width: 2px;
    height: 3px;
    border-radius: 99px;
    background: var(--accent-rose);
    transition: height 0.2s ease;
}

.vinyl-pill.is-playing .eq-bar:nth-child(1) {
    animation: eqBounce 0.75s ease-in-out infinite;
}

.vinyl-pill.is-playing .eq-bar:nth-child(2) {
    animation: eqBounce 0.55s ease-in-out 0.18s infinite;
}

.vinyl-pill.is-playing .eq-bar:nth-child(3) {
    animation: eqBounce 0.85s ease-in-out 0.32s infinite;
}

.vinyl-transport {
    display: inline-flex;
    align-items: center;
    gap: 0.12rem;
    flex-shrink: 0;
}

.vinyl-ctrl-btn {
    width: 1.68rem;
    height: 1.68rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.vinyl-ctrl-btn:hover {
    background: var(--accent-soft-bg);
    color: var(--accent-deep);
}

.vinyl-ctrl-btn:active {
    transform: scale(0.9);
}

@media (max-width: 430px) {
    #btn-vinyl-prev {
        display: none;
    }
}

/* Bang xep danh sach 11 bai nhac */
.playlist-popover {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    width: min(86vw, 19.2rem);
    border-radius: 1.25rem;
    background: var(--glass-bg-strong);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), var(--glass-inset);
    padding: 0.65rem;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-8px) scale(0.97);
    transform-origin: top left;
    transition: opacity 0.26s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.vinyl-pill-wrap.is-open .playlist-popover {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.playlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.2rem 0.45rem 0.5rem;
    border-bottom: 1px solid var(--card-hairline);
    margin-bottom: 0.35rem;
}

.playlist-heading {
    font-family: var(--font-serif);
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--accent-deep);
}

.playlist-count {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
}

.playlist-items {
    max-height: min(50dvh, 16.5rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
    padding-right: 0.15rem;
}

.playlist-items::-webkit-scrollbar {
    width: 4px;
}

.playlist-items::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 9999px;
}

.playlist-track-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.46rem 0.55rem;
    border-radius: 0.8rem;
    text-align: left;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.playlist-track-btn:hover {
    background: var(--accent-soft-bg);
}

.playlist-track-btn.is-current {
    background: var(--accent-soft-bg);
}

.playlist-track-num {
    width: 1.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

.playlist-track-btn.is-current .playlist-track-num {
    color: var(--accent-rose);
}

.playlist-track-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.playlist-track-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-track-btn.is-current .playlist-track-name {
    color: var(--accent-deep);
}

.playlist-track-desc {
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Cum nut ben phai: Dem ngay & Chuyen che do Nang Som / Dem Sao */
.top-right-group {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-shrink: 0;
}

.days-pill {
    display: none;
    align-items: center;
    gap: 0.36rem;
    padding: 0.46rem 0.82rem;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--accent-deep);
}

.days-pill.is-active {
    display: inline-flex;
}

.days-heart-svg {
    color: var(--accent-rose);
}

.theme-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    padding: 0.48rem 0.88rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-primary);
}

.theme-pill:hover {
    transform: translateY(-1px);
}

.theme-pill:active {
    transform: scale(0.95);
}

@media (max-width: 440px) {
    .days-pill {
        display: none !important;
    }
}

/* ===== Loi thi tham lo lung khi cham vao hoa 3D ===== */
.whisper-toast {
    position: fixed;
    top: calc(max(0.8rem, var(--sat) + 0.45rem) + 3.35rem);
    left: 50%;
    transform: translate3d(-50%, -8px, 0);
    z-index: 25;
    width: max-content;
    max-width: min(88vw, 25.5rem);
    padding: 0.62rem 1.15rem;
    border-radius: 1.25rem;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow), var(--glass-inset);
    text-align: center;
    font-family: var(--font-serif);
    font-size: 0.88rem;
    font-style: italic;
    line-height: 1.5;
    color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.whisper-toast.is-shown {
    opacity: 1;
    transform: translate3d(-50%, 0, 0);
}

/* ===== Thanh Dock Kinh Mo Phia Duoi ===== */
.bottom-dock-wrap {
    position: fixed;
    left: 50%;
    bottom: max(0.95rem, calc(var(--sab) + 0.65rem));
    transform: translate3d(-50%, 14px, 0);
    z-index: 45;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.38rem;
    width: max-content;
    max-width: 94vw;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.dock-capsule {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.28rem;
}

.dock-tab {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.16rem;
    padding: 0.4rem 0.74rem;
    border-radius: 1.05rem;
    font-size: 0.69rem;
    font-weight: 700;
    color: var(--text-secondary);
    transition: background-color 0.28s ease, color 0.28s ease, box-shadow 0.28s ease, transform 0.2s ease;
    white-space: nowrap;
}

@media (min-width: 480px) {
    .dock-capsule {
        gap: 0.25rem;
        padding: 0.3rem;
    }

    .dock-tab {
        flex-direction: row;
        gap: 0.4rem;
        padding: 0.5rem 0.96rem;
        border-radius: 9999px;
        font-size: 0.84rem;
    }
}

.dock-tab:hover {
    color: var(--text-primary);
}

.dock-tab.is-active {
    background: linear-gradient(135deg, #e2628b 0%, #eb7a9d 55%, #d9527c 100%);
    color: #ffffff;
    box-shadow: 0 6px 16px -3px rgba(214, 82, 124, 0.42);
}

.dock-caption {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.015em;
    color: var(--text-muted);
    text-align: center;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.dock-caption.is-dimmed {
    opacity: 0;
}

.dock-caption.is-collapsed {
    display: none;
}

@media (min-width: 640px) {
    .dock-tab {
        padding: 0.55rem 1.2rem;
        font-size: 0.89rem;
    }
}

@media (max-height: 540px) {
    .dock-caption {
        display: none;
    }

    .bottom-dock-wrap {
        bottom: max(0.5rem, var(--sab));
    }
}

/* ===== Lop Panel Trai Nghiem (Ky Niem & Tam Thu) ===== */
.sanctuary-panel {
    position: fixed;
    inset: 0;
    z-index: 35;
    display: none;
    align-items: center;
    justify-content: center;
    padding: calc(max(0.8rem, var(--sat)) + 3.05rem) 0.9rem calc(max(0.95rem, var(--sab)) + 4.15rem);
    background: var(--modal-veil);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    overscroll-behavior: contain;
}

.sanctuary-panel.is-open {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

/* ===== 1. Khong Gian Ky Niem & Thuoc Phim Cua Thu My ===== */
.memories-stage {
    position: relative;
    width: min(94vw, 25.5rem);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.55rem;
    transform: translateY(10px) scale(0.97);
    transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.sanctuary-panel.is-open .memories-stage {
    transform: translateY(0) scale(1);
}

.memories-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}

.mem-filter-group {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem;
    gap: 0.15rem;
}

.mem-filter-btn {
    padding: 0.32rem 0.68rem;
    border-radius: 9999px;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-secondary);
    transition: background-color 0.22s ease, color 0.22s ease;
    white-space: nowrap;
}

.mem-filter-btn.is-active {
    background: linear-gradient(135deg, #e2628b 0%, #d9527c 100%);
    color: #ffffff;
}

.mem-toolbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.mem-autoplay-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    padding: 0.38rem 0.72rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-primary);
}

.mem-autoplay-btn.is-playing {
    border-color: var(--accent-rose);
    color: var(--accent-deep);
}

@media (max-width: 380px) {
    #autoplay-label {
        display: none;
    }
}

.mem-close-pill {
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.mem-close-pill:hover {
    color: var(--accent-deep);
}

.polaroid-stack {
    position: relative;
    width: 100%;
}

.polaroid-stack::before,
.polaroid-stack::after {
    content: "";
    position: absolute;
    inset: 4px 8px -2px;
    border-radius: 1.25rem;
    background: var(--glass-bg-strong);
    border: 1px solid var(--card-border);
    pointer-events: none;
}

.polaroid-stack::before {
    transform: rotate(-2.5deg) translateY(2px);
    opacity: 0.52;
}

.polaroid-stack::after {
    transform: rotate(2.1deg) translateY(2px);
    opacity: 0.70;
}

.polaroid-card {
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 0.72rem 0.72rem 0.95rem;
    border-radius: 1.3rem;
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    box-shadow:
        0 24px 52px -12px rgba(48, 16, 30, 0.28),
        var(--glass-inset);
    transition: opacity 0.22s ease, transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.polaroid-card.is-switching {
    opacity: 0.38;
    transform: scale(0.988);
}

/* Khung anh thong minh: giu nguyen 100% khung hinh cua anh doc 9:16, 3:4, vuong 1:1 va ngang 16:9 */
.polaroid-photo-frame {
    position: relative;
    width: 100%;
    height: clamp(13rem, 42dvh, 21.5rem);
    border-radius: 0.92rem;
    overflow: hidden;
    background: var(--stage-surface);
    border: 1px solid var(--card-hairline);
    display: flex;
    align-items: center;
    justify-content: center;
}

.polaroid-ambient-img {
    position: absolute;
    inset: -12%;
    width: 124%;
    height: 124%;
    object-fit: cover;
    filter: blur(22px) saturate(1.15);
    opacity: 0.56;
    pointer-events: none;
    transform: translateZ(0);
}

.polaroid-media-main {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 6px 18px rgba(24, 8, 16, 0.16));
}

.polaroid-art-slot {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.polaroid-art-slot svg {
    width: 100%;
    height: 100%;
    display: block;
}

.polaroid-chip {
    position: absolute;
    top: 0.58rem;
    z-index: 3;
    padding: 0.22rem 0.62rem;
    border-radius: 9999px;
    background: rgba(24, 12, 22, 0.46);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff8fb;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    pointer-events: none;
}

.polaroid-tag-chip {
    left: 0.58rem;
}

.polaroid-counter-chip {
    right: 0.58rem;
}

.video-sound-btn {
    position: absolute;
    right: 0.58rem;
    bottom: 0.58rem;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    gap: 0.34rem;
    padding: 0.32rem 0.68rem;
    border-radius: 9999px;
    background: rgba(24, 12, 22, 0.62);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 232, 242, 0.28);
    color: #fff9fc;
    font-size: 0.68rem;
    font-weight: 700;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.video-sound-btn:hover {
    background: rgba(186, 62, 104, 0.82);
}

.video-sound-btn:active {
    transform: scale(0.94);
}

.polaroid-caption-box {
    padding: 0.72rem 0.35rem 0.05rem;
    text-align: center;
}

.polaroid-title {
    font-family: var(--font-serif);
    font-size: 1.06rem;
    font-weight: 600;
    color: var(--accent-deep);
    margin-bottom: 0.24rem;
}

.polaroid-caption {
    font-size: 0.83rem;
    font-weight: 600;
    line-height: 1.52;
    color: var(--text-secondary);
}

/* Thanh cuon phim thu nho (Filmstrip) & Nut chuyen trai/phai */
.memories-controls {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
}

.mem-nav-btn {
    width: 2.2rem;
    height: 2.2rem;
    flex-shrink: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    color: var(--text-primary);
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.mem-nav-btn:hover {
    transform: scale(1.07);
}

.mem-nav-btn:active {
    transform: scale(0.93);
}

.mem-filmstrip {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.38rem;
    overflow-x: auto;
    padding: 0.22rem 0.25rem;
    scroll-behavior: smooth;
    scrollbar-width: none;
}

.mem-filmstrip::-webkit-scrollbar {
    display: none;
}

.film-thumb {
    position: relative;
    width: 2.45rem;
    height: 2.45rem;
    flex-shrink: 0;
    border-radius: 0.56rem;
    overflow: hidden;
    border: 1.5px solid var(--card-border);
    background: var(--glass-bg);
    opacity: 0.55;
    transform: scale(0.94);
    transition: opacity 0.24s ease, transform 0.24s ease, border-color 0.24s ease, box-shadow 0.24s ease;
}

.film-thumb:hover {
    opacity: 0.85;
}

.film-thumb.is-active {
    opacity: 1;
    transform: scale(1.04);
    border-color: var(--accent-rose);
    box-shadow: 0 4px 12px rgba(217, 91, 132, 0.34);
}

.film-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.film-thumb-video {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: linear-gradient(145deg, #df638b 0%, #9b3158 100%);
    color: #fff8fb;
}

.film-thumb-video svg {
    width: 0.82rem;
    height: 0.82rem;
}

.film-thumb-badge {
    font-size: 0.54rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

/* ===== 2. Buc Tam Thu Danh Rieng Cho Thu My ===== */
.letter-sheet {
    position: relative;
    width: min(92vw, 29rem);
    max-height: 100%;
    overflow-y: auto;
    padding: 1.65rem 1.4rem 1.45rem;
    border-radius: 1.75rem;
    background: var(--card-surface);
    border: 1px solid var(--card-border);
    box-shadow:
        0 28px 64px -12px rgba(48, 16, 30, 0.30),
        var(--glass-inset);
    transform: translateY(10px) scale(0.96);
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
    -webkit-overflow-scrolling: touch;
}

.sanctuary-panel.is-open .letter-sheet {
    transform: translateY(0) scale(1);
}

.letter-sheet::before {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 1.3rem;
    border: 1px solid var(--card-hairline);
    pointer-events: none;
}

@media (min-width: 640px) {
    .letter-sheet {
        padding: 2.1rem 2.25rem 1.8rem;
    }
}

.panel-close-x {
    position: absolute;
    top: 0.9rem;
    right: 0.9rem;
    z-index: 5;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: background-color 0.2s ease, color 0.2s ease;
}

.panel-close-x:hover {
    background: var(--accent-soft-bg);
    color: var(--accent-deep);
}

.letter-crest {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: var(--font-serif);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.letter-crest::before,
.letter-crest::after {
    content: "";
    width: 1.8rem;
    height: 1px;
    background: var(--card-border);
}

.letter-salutation {
    font-family: var(--font-display);
    font-size: clamp(1.55rem, 5vw, 1.9rem);
    font-weight: 600;
    font-style: italic;
    color: var(--accent-deep);
    margin-bottom: 0.75rem;
    text-align: left;
}

.letter-body {
    font-family: var(--font-sans);
    font-size: 0.93rem;
    font-weight: 600;
    line-height: 1.74;
    color: var(--text-primary);
    text-align: left;
    white-space: pre-line;
}

@media (min-width: 640px) {
    .letter-body {
        font-size: 0.98rem;
    }
}

/* Ky thuat Ghost-Sizer CSS Grid: giu co dinh chieu cao la thu tuyet doi (Zero-CLS) */
.typewriter-stack {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
}

.typewriter-sizer,
.typewriter-live {
    grid-area: 1 / 1;
    white-space: pre-line;
}

.typewriter-sizer {
    visibility: hidden;
    pointer-events: none;
}

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

.letter-signature {
    margin-top: 1.05rem;
    font-family: var(--font-display);
    font-size: 1.28rem;
    font-weight: 600;
    font-style: italic;
    color: var(--accent-deep);
    text-align: right;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 0.45s ease, transform 0.45s ease;
}

.letter-signature.is-shown {
    opacity: 1;
    transform: translateY(0);
}

.letter-footer {
    position: relative;
    margin-top: 1.15rem;
    padding-top: 0.85rem;
    border-top: 1px dashed var(--card-hairline);
    min-height: 2.6rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.letter-skip-hint {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.letter-actions {
    display: none;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.letter-actions.is-ready {
    display: flex;
}

.btn-replay-envelope {
    display: inline-flex;
    align-items: center;
    gap: 0.36rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 0.44rem 0.72rem;
    border-radius: 9999px;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.btn-replay-envelope:hover {
    color: var(--accent-deep);
    background: var(--accent-soft-bg);
}

.btn-primary-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.52rem 1.25rem;
    border-radius: 9999px;
    font-size: 0.84rem;
    font-weight: 700;
    color: #ffffff;
    background: linear-gradient(135deg, #e2628b 0%, #eb7a9d 55%, #d9527c 100%);
    box-shadow: 0 8px 20px -4px rgba(214, 82, 124, 0.38);
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.btn-primary-action:hover {
    transform: translateY(-1px);
    box-shadow: 0 11px 24px -4px rgba(214, 82, 124, 0.46);
}

.btn-primary-action:active {
    transform: scale(0.96);
}

.letter-sheet::-webkit-scrollbar {
    width: 4px;
}

.letter-sheet::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 9999px;
}

/* ===== 3. Khuc Cuoi Cao Trao: Khong Gian 3D Tu Hoi 16 Anh Thanh Hinh Trai Tim ===== */
.heart-panel {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
}

.heart-panel:active {
    cursor: grabbing;
}

.heart-panel.is-open {
    display: block;
}

.heart-center-verse {
    position: absolute;
    top: calc(max(0.8rem, var(--sat) + 0.45rem) + 3.05rem);
    left: 50%;
    transform: translate3d(-50%, -8px, 0) scale(0.97);
    z-index: 960;
    width: max-content;
    max-width: min(93vw, 31.5rem);
    padding: 0.5rem 1.2rem 0.58rem;
    border-radius: 1.25rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(255, 248, 251, 0.92) 100%);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(230, 168, 192, 0.80);
    box-shadow:
        0 12px 30px -8px rgba(168, 68, 106, 0.18),
        0 2px 8px rgba(168, 68, 106, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.96);
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.48s ease, transform 0.56s cubic-bezier(0.22, 1, 0.36, 1), background 0.4s ease, border-color 0.4s ease;
}

html[data-theme="night"] .heart-center-verse {
    background: linear-gradient(180deg, rgba(40, 24, 49, 0.90) 0%, rgba(28, 16, 36, 0.92) 100%);
    border-color: rgba(248, 192, 216, 0.30);
    box-shadow:
        0 14px 34px -8px rgba(6, 2, 12, 0.62),
        0 2px 10px rgba(0, 0, 0, 0.32),
        inset 0 1px 0 rgba(255, 232, 242, 0.16);
}

.heart-center-verse.is-visible {
    opacity: 1;
    transform: translate3d(-50%, 0, 0) scale(1);
}

.heart-verse-kicker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    font-family: var(--font-serif);
    font-size: clamp(0.58rem, 1.45vw, 0.67rem);
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #b53864;
    margin-bottom: 0.22rem;
}

html[data-theme="night"] .heart-verse-kicker {
    color: #f69ebe;
}

.heart-verse-kicker::before,
.heart-verse-kicker::after {
    content: "";
    width: 1.2rem;
    height: 1px;
    background: rgba(208, 92, 134, 0.48);
}

html[data-theme="night"] .heart-verse-kicker::before,
html[data-theme="night"] .heart-verse-kicker::after {
    background: rgba(246, 158, 190, 0.42);
}

.heart-verse-line1 {
    font-family: var(--font-serif);
    font-size: clamp(0.79rem, 2.05vw, 0.96rem);
    font-weight: 600;
    font-style: italic;
    line-height: 1.38;
    color: #4a1d2f;
}

html[data-theme="night"] .heart-verse-line1 {
    color: #fcf2f6;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.35);
}

.heart-verse-line2 {
    font-family: var(--font-display);
    font-size: clamp(1.02rem, 2.75vw, 1.32rem);
    font-weight: 700;
    font-style: italic;
    line-height: 1.24;
    color: #9e244f;
    margin-top: 0.1rem;
}

html[data-theme="night"] .heart-verse-line2 {
    color: #ffc4d9;
    text-shadow: 0 2px 16px rgba(244, 147, 180, 0.38);
}

@media (min-width: 350px) {
    .heart-verse-line1,
    .heart-verse-line2 {
        white-space: nowrap;
    }
}

@media (max-width: 420px) {
    .heart-center-verse {
        padding: 0.44rem 0.85rem 0.52rem;
    }
}

.heart-bottom-actions {
    position: absolute;
    bottom: calc(max(0.95rem, var(--sab) + 0.65rem) + 3.4rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 950;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.heart-replay-btn {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.38rem;
    padding: 0.38rem 0.92rem;
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--accent-deep);
}

.heart-replay-btn:hover {
    transform: translateY(-1px);
}

.heart-replay-btn:active {
    transform: scale(0.95);
}

.heart-space-stage {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.heart-node-card {
    position: absolute;
    left: 50%;
    top: 50%;
    padding: 3px 3px 8px;
    border-radius: 0.55rem;
    background: var(--glass-bg-strong);
    border: 1px solid var(--card-border);
    box-shadow:
        0 10px 24px -6px rgba(24, 8, 18, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 0.65);
    pointer-events: auto;
    cursor: pointer;
    will-change: transform, opacity;
    transition: border-color 0.22s ease, box-shadow 0.22s ease;
}

.heart-node-card:hover {
    border-color: var(--accent-rose);
    box-shadow:
        0 14px 30px -4px rgba(226, 98, 139, 0.48),
        0 0 16px rgba(244, 147, 180, 0.38);
}

.heart-node-photo {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 0.36rem;
    overflow: hidden;
    background: var(--stage-surface);
}

.heart-node-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 22%;
    display: block;
    pointer-events: none;
}

/* Khung ngam anh can canh khi cham vao bat ky tam anh nao tren Trai Tim 3D */
.heart-spotlight {
    position: absolute;
    inset: 0;
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: calc(max(0.8rem, var(--sat)) + 3.1rem) 1rem calc(max(0.95rem, var(--sab)) + 4.4rem);
    background: var(--modal-veil);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: default;
}

.heart-spotlight.is-open {
    display: flex;
}

.heart-spotlight-card {
    width: min(92vw, 24.5rem);
    animation: spotPopIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.heart-spotlight-frame {
    height: clamp(13rem, 40dvh, 20.5rem);
}

.spot-close-btn {
    position: absolute;
    right: 0.58rem;
    bottom: 0.58rem;
    z-index: 5;
    width: 2.05rem;
    height: 2.05rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(24, 12, 22, 0.62);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 232, 242, 0.28);
    color: #fff9fc;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.spot-close-btn:hover {
    background: rgba(186, 62, 104, 0.85);
    transform: scale(1.06);
}

.spot-nav-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.65rem;
    padding-top: 0.55rem;
    border-top: 1px dashed var(--card-hairline);
}

.spot-hint-text {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
}

@keyframes spotPopIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===== Hat sang & canh tim vector nho khi cham ===== */
.heart-burst-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.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;
}

/* ===== Keyframes hoat anh muot tren GPU ===== */
@keyframes envelopeFloat {
    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }

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

@keyframes vinylSpin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@keyframes eqBounce {
    0%,
    100% {
        height: 3px;
    }

    50% {
        height: 10px;
    }
}

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

    50% {
        opacity: 0.2;
    }
}

@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));
    }
}

@media (prefers-reduced-motion: reduce) {
    .envelope-card,
    .vinyl-disc-btn,
    .eq-bar {
        animation: none !important;
    }
}
