:root {
    --night-sky: #0F172A;
    --deep-slate: #1E293B;
    --emerald: #064E3B;
    --gold: #F97316;
    --light-gold: #FDBA74;
    --warm-gold: #EA580C;
    --text-light: #F8FAFC;
    --text-muted: #94A3B8;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Tajawal', sans-serif;
    background: radial-gradient(circle at center, var(--deep-slate) 0%, var(--night-sky) 100%);
    color: var(--text-light);
    overflow: hidden;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

body.intro-complete {
    overflow-y: auto;
    height: auto;
    min-height: 100dvh;
    align-items: stretch;
}

/* ── Preloader ── */
#preloader {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#preloader p {
    color: var(--text-light);
    font-size: 0.85rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    opacity: 0.5;
}

.progress-container {
    width: 250px;
    height: 4px;
    background: #222;
    border-radius: 4px;
    overflow: hidden;
}

#progress-bar {
    width: 0%;
    height: 100%;
    background: #dc2626;
    transition: width 0.3s ease;
}

/* ── Splash ── */
#splash-screen {
    position: fixed;
    inset: 0;
    background: var(--night-sky);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
}

.splash-element {
    text-align: center;
    opacity: 0;
}

.splash-welcome {
    font-size: 2rem;
    font-weight: 300;
    color: var(--light-gold);
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 0.5rem;
}

.splash-name {
    font-size: 4rem;
    font-weight: 800;
    color: var(--text-light);
    display: block;
    margin-top: 0.5rem;
}

/* ── Pattern overlay ── */
.pattern-overlay {
    position: absolute;
    inset: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='1'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    z-index: 1;
    pointer-events: none;
}

/* ── Main scene ── */
#main-scene {
    width: 100%;
    height: 100%;
    position: relative;
    opacity: 0;
}

body.intro-complete #main-scene {
    min-height: 100dvh;
    height: auto;
}

#stars-container {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.star {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 6px 1px rgba(255, 255, 255, 0.5);
}

/* ── Lanterns ── */
.lantern {
    position: absolute;
    top: 0;
    z-index: 10;
    opacity: 0;
    transform-origin: top center;
}

.lantern-right {
    right: 15%;
    width: 5rem;
}

.lantern-left {
    left: 15%;
    width: 3.5rem;
}

.lantern svg {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 0 12px rgba(212, 175, 55, 0.35));
}

/* ── Main content ── */
#main-content {
    position: relative;
    z-index: 20;
    text-align: center;
    padding: 2rem 1.5rem 7rem;
    max-width: 700px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1.5rem;
}

body.intro-complete #main-content {
    justify-content: flex-start;
    min-height: 100dvh;
    height: auto;
    padding-top: 1.2rem;
}

.takabal-text {
    font-size: 1.5rem;
    font-weight: 300;
    color: rgba(253, 230, 138, 0.8);
    letter-spacing: 0.05em;
    opacity: 0;
}

/* ── Calligraphy stage ── */
#calligraphy-stage {
    width: 100%;
    max-width: 560px;
    height: 336px;
    /* 280 * 1.2 */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.9);
    transform-origin: center center;
}

#eid-text-container {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 18px rgba(212, 175, 55, 0.6));
}

/* ── Sender phrase ── */
#sender-phrase {
    opacity: 0;
    text-align: center;
    margin-top: 0.25rem;
}

#sender-phrase svg text {
    font-family: 'Tajawal', sans-serif;
    font-size: 22px;
    font-weight: 500;
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 0.6;
    paint-order: stroke fill;
}

#sender-phrase svg text.draw {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: draw-stroke 2.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

#sender-phrase svg text.fill-in {
    /* Keep stroke fully drawn while fill fades in — prevents flash */
    stroke-dasharray: 1200;
    stroke-dashoffset: 0;
    fill: transparent;
    animation: fade-fill 0.6s ease forwards;
}

@keyframes draw-stroke {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes fade-fill {
    from {
        fill: transparent;
        stroke: var(--text-muted);
    }

    to {
        fill: var(--text-muted);
        stroke: none;
    }
}

/* ── Recipient name ── */
.recipient-block {
    opacity: 0;
    font-size: 1.3rem;
    font-weight: 300;
    color: var(--text-muted);
    line-height: 1.8;
}

#recipient-name {
    display: inline-block;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--gold);
    border-bottom: 2px dashed rgba(212, 175, 55, 0.4);
    padding: 0 0.5rem;
    min-width: 80px;
    outline: none;
    cursor: text;
    transition: border-color 0.3s, background 0.3s;
    border-radius: 4px;
}

#recipient-name:focus,
#recipient-name:hover {
    border-bottom-color: var(--gold);
    background: rgba(212, 175, 55, 0.08);
}

/* ── Bottom nav ── */
#bottom-nav {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(6rem);
    width: 90%;
    max-width: 400px;
    height: 5rem;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(100, 116, 139, 0.35);
    border-radius: 30px;
    z-index: 50;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 0.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    opacity: 0;
}

#nav-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 4rem;
    height: 4rem;
    background: rgba(212, 175, 55, 0.18);
    border-radius: 50%;
    border: 1px solid rgba(212, 175, 55, 0.4);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.25);
    left: 0;
    z-index: 0;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.nav-item {
    position: relative;
    width: 4rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    z-index: 1;
    color: var(--text-muted);
}

.nav-item .icon-wrapper {
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55), color 0.3s;
}

.nav-item .nav-text {
    opacity: 0;
    transform: translateY(12px);
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    position: absolute;
    bottom: 12px;
    font-size: 0.6rem;
    font-weight: 700;
    white-space: nowrap;
    font-family: 'Tajawal', sans-serif;
}

.nav-item.active .icon-wrapper {
    transform: translateY(-8px);
    color: var(--text-light);
}

.nav-item.active .nav-text {
    opacity: 1;
    transform: translateY(0);
    color: var(--text-light);
}

/* ── Toast ── */
#toast {
    position: fixed;
    bottom: 7rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(6, 78, 59, 0.95);
    color: var(--light-gold);
    padding: 0.6rem 1.4rem;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: 'Tajawal', sans-serif;
    opacity: 0;
    pointer-events: none;
    z-index: 9000;
    transition: opacity 0.3s, transform 0.3s;
    border: 1px solid rgba(212, 175, 55, 0.3);
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Responsive ── */
@media (max-width: 480px) {

    /* Splash screen */
    .splash-name {
        font-size: 2.5rem;
    }

    /* Animation stage */
    #calligraphy-stage {
        height: 220px;
        max-width: 100%;
        margin-bottom: 1.5rem;
    }

    /* Main content */
    #main-content {
        padding: 1rem 1rem 6.25rem;
        gap: 0.95rem;
        overflow: visible;
    }

    body.intro-complete #main-content {
        padding: 0.8rem 0.9rem 5.8rem;
        gap: 0.8rem;
    }

    /* Greeting message text - improved readability */
    #sender-phrase {
        margin: 0.5rem auto;
        max-width: 90vw;
    }

    #sender-phrase svg {
        height: auto;
    }

    #sender-phrase svg text {
        font-size: 14px;
        stroke-width: 0.5;
    }

    .takabal-text {
        font-size: 1.2rem;
        line-height: 1.4;
        margin-bottom: 0.5rem;
    }

    /* Recipient name */
    #recipient-name {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }

    /* Reply card improvements */
    #reply-wrap {
        margin-bottom: 1.5rem;
    }

    .reply-card {
        padding: 1.2rem;
        gap: 0.75rem;
        border-radius: 16px;
    }

    .reply-label {
        font-size: 0.9rem;
    }

    #reply-input {
        font-size: 0.95rem;
        padding: 0.75rem;
        min-height: 80px;
    }

    #reply-chars {
        font-size: 0.8rem;
    }

    #reply-submit {
        font-size: 0.9rem;
        padding: 0.75rem 1.5rem;
    }

    /* Lanterns smaller on mobile */
    .lantern-right {
        width: 3rem;
        right: 10%;
    }

    .lantern-left {
        width: 2.2rem;
        left: 10%;
    }

    /* Navigation improvements */
    #bottom-nav {
        height: 3.5rem;
        padding: 0.5rem 0;
    }

    .nav-item {
        font-size: 0.75rem;
    }

    .nav-icon {
        width: 24px;
        height: 24px;
    }

    /* Recipient block spacing */
    .recipient-block {
        gap: 0.8rem;
    }

    .relation-tag {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }

    .custom-msg {
        font-size: 0.92rem !important;
        line-height: 1.52 !important;
    }

    #replies-carousel {
        position: relative;
        bottom: auto;
        left: auto;
        transform: none;
        width: 100%;
        max-width: 100%;
        height: 84px;
        margin-top: 0.2rem;
        margin-bottom: 0.35rem;
        pointer-events: none;
        z-index: 5;
    }

    #reply-wrap {
        margin-bottom: 0;
    }

    #app-footer {
        font-size: 0.65rem;
    }
}

.reply-empty {
    position: absolute;
    inset: 0;
    border-radius: 18px;
    border: 1px dashed rgba(212, 175, 55, 0.25);
    background: rgba(30, 41, 59, 0.55);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0 0.8rem;
}

/* ── Replies carousel ── */
#replies-carousel {
    position: fixed;
    bottom: 8rem;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 420px;
    height: 88px;
    z-index: 100;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

#replies-carousel.visible {
    opacity: 1;
}

.reply-card-slide {
    position: absolute;
    inset: 0;
    background: rgba(6, 78, 59, 0.88);
    border: 1px solid rgba(212, 175, 55, 0.3);
    border-radius: 18px;
    padding: 0.75rem 1rem;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    overflow: hidden;
    transition: opacity 0.55s ease, transform 0.55s cubic-bezier(0.34, 1.1, 0.64, 1);
    will-change: transform, opacity;
}

.reply-card-slide.state-active {
    opacity: 1;
    transform: translateY(0) scale(1);
    z-index: 3;
}

.reply-card-slide.state-behind1 {
    opacity: 0.55;
    transform: translateY(7px) scale(0.965);
    z-index: 2;
}

.reply-card-slide.state-behind2 {
    opacity: 0.25;
    transform: translateY(12px) scale(0.932);
    z-index: 1;
}

.reply-card-slide.state-leaving {
    opacity: 0;
    transform: translateY(-22px) scale(0.96);
    z-index: 4;
}

.reply-card-slide.state-hidden {
    opacity: 0;
    transform: translateY(18px) scale(0.92);
    z-index: 0;
}

.reply-card-name {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-light);
    letter-spacing: 0.03em;
}

.reply-card-msg {
    font-size: 0.87rem;
    color: var(--light-gold);
    overflow: hidden;
    display: -webkit-box;
    /* -webkit-line-clamp: 2; */
    -webkit-box-orient: vertical;
    line-height: 1.45;
    font-weight: 400;
}

/* ── Reply box ── */
#reply-wrap {
    width: 100%;
    max-width: 480px;
    opacity: 0;
    transform: translateY(24px);
}

#reply-wrap.visible {
    opacity: 1;
    transform: translateY(0);
}

.reply-card {
    background: rgba(30, 41, 59, 0.75);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 20px;
    padding: 1.1rem 1.25rem 1rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.reply-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    display: block;
}

#reply-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(212, 175, 55, 0.2);
    border-radius: 12px;
    color: var(--text-light);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.95rem;
    font-weight: 400;
    padding: 0.7rem 0.9rem;
    resize: none;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
    line-height: 1.6;
    min-height: 72px;
    max-height: 120px;
}

#reply-input::placeholder {
    color: rgba(148, 163, 184, 0.45);
}

#reply-input:focus {
    border-color: rgba(212, 175, 55, 0.5);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.08);
}

.reply-footer {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-top: 0.65rem;
    gap: 0.6rem;
}

#reply-submit {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: linear-gradient(135deg, var(--gold), var(--warm-gold));
    color: var(--night-sky);
    font-family: 'Tajawal', sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    padding: 0.5rem 1.2rem;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

#reply-submit:hover {
    opacity: 0.88;
    transform: translateY(-2px);
}

#reply-submit:active {
    transform: scale(0.96);
}

#reply-submit:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.reply-char-count {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-right: auto;
}

/* ── Footer ── */
#app-footer {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 400px;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(148, 163, 184, 0.7);
    opacity: 0;
    z-index: 40;
    transition: opacity 0.5s ease;
    pointer-events: none;
    letter-spacing: 0.03em;
}

#app-footer.visible {
    opacity: 1;
}

body.intro-complete #app-footer {
    position: relative;
    bottom: auto;
    transform: none;
    width: 100%;
    max-width: none;
    padding-bottom: 1.5rem;
    margin-top: 2rem;
    opacity: 1;
}