/* ============================================
   BASE STYLES & RESETS
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Quicksand', sans-serif;
    background-color: #faf7f2;
    color: #4a3f35;
    overflow-x: hidden;
    min-height: 100vh;
    padding-bottom: 6rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    scroll-snap-type: y mandatory;
}

html.intro-lock,
html.intro-lock body,
body.intro-lock {
    overflow: hidden;
    height: 100%;
    overscroll-behavior: none;
    touch-action: none;
}

/* ============================================
   CUSTOM SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #faf7f2;
}

::-webkit-scrollbar-thumb {
    background: #d4c5b9;
    border-radius: 10px;
}

/* ============================================
   CANVAS PARTICLES
   ============================================ */
#canvas-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* ============================================
   INTRO SCREEN
   ============================================ */
.intro-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #faf7f2;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 1.5rem;
    transition: all 1.1s ease-in-out;
    touch-action: none;
    overscroll-behavior: none;
}

.intro-card {
    text-align: center;
    max-width: 24rem;
}

.intro-card > * + * {
    margin-top: 1.5rem;
}

.intro-subtitle {
    font-size: 0.875rem;
    color: #8c7460;
    letter-spacing: 0.05em;
    display: block;
    opacity: 0;
    transform: translateY(-10px);
    animation: introFadeDown var(--intro-subtitle-duration, 0.8s) ease forwards;
    animation-delay: var(--intro-subtitle-delay, 0.3s);
}

.intro-name {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: clamp(2.5rem, 9vw, 5rem);
    line-height: 1.2;
    color: #5c4d40;
    font-weight: 600;
    opacity: 0;
    animation: introWrite var(--intro-name-duration, 1.2s) ease forwards;
    animation-delay: var(--intro-name-delay, 0.8s);
}

.intro-wish {
    font-size: 0.875rem;
    color: #8c7460;
    font-style: italic;
    opacity: 0;
    transform: translateY(10px);
    animation: introFadeUp var(--intro-wish-duration, 0.8s) ease forwards;
    animation-delay: var(--intro-wish-delay, 1.6s);
}

.intro-tap-hint {
    position: absolute;
    bottom: 2rem;
    font-size: 0.75rem;
    color: #8c7460;
    letter-spacing: 0.05em;
    opacity: 0;
    animation: introPulse 2s ease-in-out infinite;
    animation-delay: var(--intro-hint-delay, 2.5s);
}

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

/* ============================================
   FAB BUTTONS (Share/Audio)
   ============================================ */
.fab-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.fab-btn {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 9999px;
    background-color: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    color: #6b5a4c;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border: 1px solid #e8dfd8;
    cursor: pointer;
    transition: transform 0.25s ease, background-color 0.25s ease;
}

.fab-btn:hover {
    background-color: rgba(255, 255, 255, 0.8);
}

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

.fab-btn i {
    font-size: 0.875rem;
}

/* ============================================
   PROGRESS DOTS
   ============================================ */
.progress-dots {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.progress-dot {
    position: relative;
    width: 8px;
    height: 8px;
    padding: 0;
    border: none;
    appearance: none;
    border-radius: 999px;
    background-color: #e3cdc1;
    transition: all 0.4s ease;
    cursor: pointer;
}

.progress-dot::before {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 999px;
}

.progress-dot.active {
    background-color: #8c7460;
    height: 22px;
}

/* ============================================
   HEADER
   ============================================ */
.header {
    max-width: 42rem;
    margin: 0 auto;
    padding: 5rem 1.5rem 3rem;
    text-align: center;
}

.header-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #9c8470;
    font-weight: 600;
    margin-bottom: 0.75rem;
    display: block;
}

.header-title {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: 1.875rem;
    color: #5c4d40;
    line-height: 1.375;
}

.header-subtitle {
    font-size: 0.75rem;
    color: #8c7460;
    margin-top: 0.75rem;
    font-weight: 500;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main {
    max-width: 42rem;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.main > * + * {
    margin-top: 8rem;
}

/* ============================================
   SCROLL SNAPPING
   ============================================ */
.header,
.main > section,
.footer {
    scroll-snap-align: start;
    scroll-snap-stop: normal;
}

.main > .candle-section {
    scroll-snap-align: center;
}

/* ============================================
   ENVELOPE SECTION
   ============================================ */
.envelope-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 0;
}

.envelope-wrapper {
    position: relative;
    width: 100%;
    max-width: 420px;
    aspect-ratio: 420 / 280;
    margin: 0 auto;
    cursor: pointer;
    perspective: 1000px;
}

.envelope-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 420px;
    height: 280px;
    transform-origin: top left;
}

.envelope {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: #e3cdc1;
    border-radius: 8px;
    box-shadow: 0 15px 35px rgba(74, 63, 53, 0.08);
    transition: transform 0.5s ease;
}

.envelope-front {
    position: absolute;
    width: 0;
    height: 0;
    border-top: 140px solid transparent;
    border-bottom: 140px solid #e3cdc1;
    border-left: 210px solid #ecdcd3;
    border-right: 210px solid #ecdcd3;
    border-radius: 8px;
    z-index: 3;
    pointer-events: none;
}

.envelope-flap {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 210px solid transparent;
    border-right: 210px solid transparent;
    border-top: 140px solid #dfc5b7;
    transform-origin: top;
    transition: transform 0.5s ease, z-index 0.2s ease;
    z-index: 4;
    top: 0;
}

.letter {
    position: absolute;
    left: 5%;
    bottom: 5px;
    width: 90%;
    height: 85%;
    background-color: #ffffff;
    border-radius: 6px;
    padding: 24px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 2;
    overflow: hidden;
    color: #5c4d40;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.envelope-wrapper.open .envelope-flap {
    transform: rotateX(180deg);
    z-index: 1;
}

.envelope-wrapper.open .letter {
    transform: translateY(-130px);
    z-index: 5;
    height: auto;
    min-height: 250px;
    box-shadow: 0 20px 40px rgba(74, 63, 53, 0.12);
}

.letter-header {
    border-bottom: 1px solid #f3ece6;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.letter-from {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: calc(0.875rem / var(--env-scale, 1));
    color: #8c7460;
}

.letter-date {
    font-size: calc(0.75rem / var(--env-scale, 1));
    color: #8c7460;
}

.letter-body p {
    font-size: calc(0.8125rem / var(--env-scale, 1));
    line-height: 1.625;
    margin-bottom: 1rem;
    text-align: justify;
}

.letter-body p:last-child {
    margin-bottom: 0;
}

.letter-footer {
    margin-top: 1.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid #f3ece6;
    text-align: right;
}

.letter-sign {
    font-family: 'Caveat', cursive;
    font-size: calc(1.5rem / var(--env-scale, 1));
    color: #8c7460;
    display: block;
}

.letter-from-label {
    font-size: calc(11px / var(--env-scale, 1));
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8c7460;
}

.envelope-hint {
    font-size: 11px;
    color: #9c8470;
    margin-top: 1rem;
    font-style: italic;
    transition: opacity 300ms;
}

/* ============================================
   CANDLE SECTION
   ============================================ */
.candle-section {
    max-width: 28rem;
    margin: 0 auto;
    padding: 2rem;
    border-radius: 1rem;
    background-color: rgba(255, 255, 255, 0.4);
    border: 1px solid #f0e6de;
    text-align: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.candle-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.125rem;
    color: #5c4d40;
    margin-bottom: 1.5rem;
}

.candle-container {
    position: relative;
    width: 4rem;
    height: 7rem;
    margin: 0 auto 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

.candle-flame {
    width: 1rem;
    height: 1.5rem;
    background: linear-gradient(to top, #fb923c, #fde68a);
    border-radius: 9999px;
    margin-bottom: 0.25rem;
    animation: breathe 2s ease-in-out infinite;
}

.candle-wick {
    width: 0.125rem;
    height: 0.5rem;
    background-color: #4b5563;
}

.candle-body {
    width: 1.5rem;
    height: 4rem;
    background-color: #e3cdc1;
    border-radius: 0.125rem 0.125rem 0 0;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;
}

.candle-body-top {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 0.5rem;
    background-color: #dfc5b7;
}

.candle-base {
    width: 3rem;
    height: 0.25rem;
    background-color: #d4c5b9;
    border-radius: 9999px;
}

.candle-status {
    font-size: 0.75rem;
    color: #8c7460;
    margin-bottom: 1rem;
}

.candle-btn {
    padding: 0.5rem 1.25rem;
    background-color: #8c7460;
    color: #faf7f2;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    letter-spacing: 0.05em;
    border: none;
    cursor: pointer;
    transition: all 150ms;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.candle-btn:hover {
    background-color: #735e4d;
}

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

.candle-btn.blown {
    background-color: #d4c5b9;
    color: #735e4d;
    cursor: default;
}

/* ============================================
   GALLERY SECTION
   ============================================ */
.gallery-section {
    padding: 2rem 0;
}

.gallery-section > * + * {
    margin-top: 2rem;
}

.gallery-title {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: 1.25rem;
    color: #5c4d40;
    text-align: center;
    margin-bottom: 2rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 2rem;
    max-width: 32rem;
    margin: 0 auto;
}

.polaroid-card {
    background-color: #ffffff;
    padding: 1rem 1rem 1.5rem;
    border-radius: 0.125rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border: 1px solid #e8dfd8;
    transition: transform 0.35s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.35s ease;
}

.polaroid-card:nth-child(1) {
    transform: rotate(-1.5deg);
}

.polaroid-card:nth-child(2) {
    transform: rotate(1.5deg);
}

.polaroid-card:nth-child(3) {
    transform: rotate(0deg);
}

.polaroid-card:hover {
    transform: translateY(-6px) rotate(0deg) scale(1.02);
    box-shadow: 0 18px 30px rgba(74, 63, 53, 0.14);
}

.polaroid-img {
    aspect-ratio: 1 / 1;
    background-color: #f5ebe6;
    border-radius: 0.125rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #c2b0a2;
    margin-bottom: 0.75rem;
    position: relative;
    overflow: hidden;
}

.polaroid-img i {
    font-size: 1.875rem;
}

.polaroid-emoji {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    font-size: 0.75rem;
}

.polaroid-title {
    font-family: 'Caveat', cursive;
    font-size: 1.25rem;
    text-align: center;
    color: #735e4d;
    margin-bottom: 0.25rem;
}

.polaroid-subtitle {
    font-size: 11px;
    text-align: center;
    letter-spacing: 0.1em;
    color: #8c7460;
}

/* ============================================
   AFFIRMATION SECTION
   ============================================ */
.affirmation-section {
    max-width: 28rem;
    margin: 0 auto;
    text-align: center;
    padding: 2rem 0;
}

.affirmation-section > * + * {
    margin-top: 1rem;
}

.affirmation-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: #8c7460;
}

.affirmation-box {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 1rem;
    border: 1px solid #f0e6de;
    transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.25, 1, 0.5, 1), filter 0.55s ease;
}

.affirmation-box.fading {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
    filter: blur(3px);
}

.affirmation-text {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    color: #735e4d;
    font-size: 1rem;
    line-height: 1.625;
}

.affirmation-btn {
    font-size: 11px;
    color: #8c7460;
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    letter-spacing: 0.05em;
    transition: color 150ms;
}

.affirmation-btn:hover {
    color: #735e4d;
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
    margin-top: 6rem;
    text-align: center;
    font-size: 11px;
    letter-spacing: 0.05em;
    color: #8c7460;
}

.footer-quote {
    font-family: 'Playfair Display', serif;
    font-style: italic;
}

.footer-copy {
    margin-top: 0.5rem;
}

/* ============================================
   MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(74, 63, 53, 0.2);
    backdrop-filter: blur(2px);
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1.5rem;
    opacity: 0;
    transition: opacity 300ms;
}

.modal-card {
    background-color: #faf7f2;
    border: 1px solid #e8dfd8;
    padding: 2rem;
    border-radius: 1rem;
    max-width: 24rem;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    transform: scale(0.95);
    transition: transform 300ms;
}

.modal-emoji {
    font-size: 1.875rem;
    display: block;
    margin-bottom: 0.75rem;
}

.modal-title {
    font-family: 'Playfair Display', serif;
    color: #5c4d40;
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.modal-desc {
    font-size: 0.75rem;
    color: #7c695a;
    line-height: 1.625;
    margin-bottom: 1.5rem;
}

.modal-btn {
    padding: 0.5rem 1.5rem;
    background-color: #8c7460;
    color: #faf7f2;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    transition: all 150ms;
}

.modal-btn:hover {
    background-color: #735e4d;
}

/* ============================================
   SCROLL REVEAL
   ============================================ */
.reveal {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 0.9s cubic-bezier(0.25, 1, 0.5, 1), transform 0.9s cubic-bezier(0.25, 1, 0.5, 1);
}

.reveal.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes breathe {
    0%, 100% {
        transform: scale(1);
        opacity: 0.9;
    }
    50% {
        transform: scale(1.05);
        opacity: 1;
        filter: drop-shadow(0 0 8px rgba(253, 186, 116, 0.6));
    }
}

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

@keyframes introFadeDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes introWrite {
    0% {
        opacity: 0;
        transform: scale(0.95);
        filter: blur(4px);
    }
    50% {
        opacity: 0.5;
        filter: blur(2px);
    }
    100% {
        opacity: 1;
        transform: scale(1);
        filter: blur(0);
    }
}

@keyframes introFadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes introFadeScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.fa-spin {
    animation: spin 1s linear infinite;
}

/* ============================================
   FOCUS STATES
   ============================================ */
.fab-btn:focus-visible,
.progress-dot:focus-visible,
.candle-btn:focus-visible,
.modal-btn:focus-visible,
.affirmation-btn:focus-visible {
    outline: 2px solid #8c7460;
    outline-offset: 3px;
}

.envelope-wrapper:focus-visible {
    outline: 2px solid #8c7460;
    outline-offset: 6px;
    border-radius: 8px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (min-width: 768px) {
    .header-title {
        font-size: 2.25rem;
    }

    .letter-body p {
        font-size: calc(0.875rem / var(--env-scale, 1));
    }

    .gallery-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .progress-dots {
        right: 10px;
        gap: 10px;
    }

    .progress-dot {
        width: 6px;
        height: 6px;
    }

    .progress-dot.active {
        height: 16px;
    }
}