/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   messages.css — Interactive Star Note Board
   Mobile-first, full-viewport cosmic aesthetic
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */

/* ── Font roles for Star Notes ──────────────
   Cinzel            → titles, labels, counters
   Exo 2             → UI buttons, numbers
   Outfit            → body text, inputs, popups
   Cormorant Garamond → poetic hint text
── */
body[data-page="messages"] {
    font-family: 'Outfit', sans-serif;
}

/* Starfield fills the whole viewport */
.starfield {
    position: fixed;
    inset: 0;
    cursor: default;
    overflow: hidden;
    background: radial-gradient(ellipse at 30% 40%, #120a18 0%, #08080f 60%, #020208 100%);
    z-index: 0;
}

.starfield.is-placing {
    cursor: crosshair;
}

/* ── Decorative background stars (JS-generated) ── */
.bg-stars {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.bg-star {
    position: absolute;
    border-radius: 50%;
    background: rgba(234, 233, 239, 0.55);
    animation: twinkle linear infinite;
}

@keyframes twinkle {
    0%,  100% { opacity: 0.25; transform: scale(1); }
    50%        { opacity: 1;    transform: scale(1.6); }
}

/* ── Center hint — fades when stars appear ── */
.field-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.8s ease;
    animation: hint-float 3s ease-in-out infinite;
}

.field-hint.hint-hide { opacity: 0; }

.field-hint p {
    color: rgba(234, 233, 239, 0.4);
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem;
    letter-spacing: 0.06em;
    font-style: italic;
    margin: 0;
}

@keyframes hint-float {
    0%, 100% { transform: translate(-50%, -50%) translateY(0);    opacity: 0.7; }
    50%       { transform: translate(-50%, -50%) translateY(-8px); opacity: 1;   }
}

/* ── Star counter (top-right) ── */
.star-counter {
    position: fixed;
    top: 1.2rem;
    right: max(0.8rem, env(safe-area-inset-right, 0px));
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.counter-number {
    font-size: 1.5rem;
    font-weight: 700;
    font-family: 'Cormorant Garamond', serif;
    color: rgba(234, 233, 239, 0.55);
    letter-spacing: -0.04em;
    line-height: 1;
}

.counter-label {
    font-size: 0.62rem;
    font-family: 'Cormorant Garamond', serif;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(234, 233, 239, 0.25);
}

.audio-toggle {
    margin-top: 0.42rem;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid rgba(234, 233, 239, 0.22);
    border-radius: 999px;
    background: rgba(8, 12, 20, 0.5);
    color: rgba(234, 233, 239, 0.72);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    cursor: pointer;
    pointer-events: auto;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.audio-toggle:hover,
.audio-toggle:focus-visible {
    border-color: rgba(234, 233, 239, 0.42);
    color: rgba(255, 255, 255, 0.95);
    background: rgba(16, 22, 34, 0.72);
    transform: translateY(-1px);
}

.audio-toggle:focus-visible {
    outline: 2px solid rgba(175, 202, 227, 0.7);
    outline-offset: 2px;
}

.audio-toggle.is-muted {
    border-color: rgba(234, 233, 239, 0.14);
    color: rgba(234, 233, 239, 0.4);
    background: rgba(8, 12, 20, 0.32);
}

.audio-toggle-icon {
    width: 0.9rem;
    height: 0.9rem;
    object-fit: contain;
    display: block;
    opacity: 0.85;
    transition: opacity 0.2s ease;
}

.audio-toggle.is-muted .audio-toggle-icon {
    opacity: 0.35;
    filter: grayscale(1);
}

/* ── Notes layer ── */
.notes-layer {
    position: absolute;
    inset: 0;
    z-index: 3;
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   Note Star component
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.note-star {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 4;
    cursor: pointer;
    outline: none;
}

/* Expanding pulse ring */
.star-pulse {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    border: 1px solid rgba(234, 233, 239, 0.12);
    animation: pulse-ring 2.8s ease-out infinite;
    pointer-events: none;
}

.note-star:hover .star-pulse,
.note-star.is-open .star-pulse {
    border-color: rgba(234, 233, 239, 0.35);
}

@keyframes pulse-ring {
    0%   { transform: scale(0.7); opacity: 0.9; }
    100% { transform: scale(2.4); opacity: 0; }
}

/* The glow dot */
.star-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #eae9ef;
    box-shadow: 0 0 5px #eae9ef, 0 0 10px rgba(234, 233, 239, 0.35);
    position: relative;
    z-index: 1;
    transition: box-shadow 0.2s ease, background 0.2s ease;
}

.note-star:hover .star-dot,
.note-star.is-open .star-dot {
    background: #fff;
    box-shadow: 0 0 8px #fff, 0 0 20px #fff, 0 0 40px rgba(122, 20, 40, 0.7);
}

/* ── Note popup (tooltip above the star) ── */
.star-popup {
    position: absolute;
    bottom: calc(100% + 16px);
    left: 50%;
    --popup-shift-x: 0px;
    --popup-shift-y: 0px;
    transform: translateX(calc(-50% + var(--popup-shift-x))) translateY(var(--popup-shift-y)) scale(0.85) translateY(4px);
    min-width: 180px;
    max-width: min(240px, calc(100vw - 24px));
    background:
        linear-gradient(180deg, rgba(18, 24, 34, 0.95) 0%, rgba(8, 12, 20, 0.95) 100%);
    border: 1px solid rgba(141, 171, 198, 0.34);
    border-radius: 0.5rem;
    padding: 0.85rem 0.95rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(2, 5, 11, 0.5), 0 0 0 1px rgba(120, 152, 183, 0.08) inset;
    z-index: 10;
    white-space: normal;
    word-break: break-word;
}

/* Popup arrow pointing down */
.star-popup::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(234, 233, 239, 0.16);
}

.note-star.is-open .star-popup {
    opacity: 1;
    transform: translateX(calc(-50% + var(--popup-shift-x))) translateY(var(--popup-shift-y)) scale(1) translateY(0);
    pointer-events: auto;
}

/* Stars near top of screen: popup below */
.note-star.popup-below .star-popup {
    bottom: auto;
    top: calc(100% + 16px);
    transform: translateX(calc(-50% + var(--popup-shift-x))) translateY(var(--popup-shift-y)) scale(0.85) translateY(-4px);
}

.note-star.popup-below .star-popup::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: rgba(234, 233, 239, 0.16);
}

.note-star.popup-below.is-open .star-popup {
    transform: translateX(calc(-50% + var(--popup-shift-x))) translateY(var(--popup-shift-y)) scale(1) translateY(0);
}

.note-star.popup-left .star-popup {
    left: auto;
    right: 0;
    transform: translateX(var(--popup-shift-x)) translateY(var(--popup-shift-y)) scale(0.85) translateY(4px);
}

.note-star.popup-left .star-popup::after {
    left: auto;
    right: 8px;
    transform: none;
}

.note-star.popup-left.is-open .star-popup {
    transform: translateX(var(--popup-shift-x)) translateY(var(--popup-shift-y)) scale(1) translateY(0);
}

.note-star.popup-right .star-popup {
    left: 0;
    transform: translateX(var(--popup-shift-x)) translateY(var(--popup-shift-y)) scale(0.85) translateY(4px);
}

.note-star.popup-right .star-popup::after {
    left: 8px;
    transform: none;
}

.note-star.popup-right.is-open .star-popup {
    transform: translateX(var(--popup-shift-x)) translateY(var(--popup-shift-y)) scale(1) translateY(0);
}

.popup-author {
    font-size: 0.68rem;
    font-family: 'Exo 2', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(175, 202, 227, 0.88);
    margin: 0 0 0.35rem;
}

.popup-msg {
    font-family: 'Outfit', sans-serif;
    font-size: 0.88rem;
    color: rgba(230, 236, 244, 0.95);
    line-height: 1.55;
    margin: 0 0 0.5rem;
}

.popup-gif {
    width: 100%;
    max-height: 160px;
    object-fit: cover;
    border-radius: 0.4rem;
    margin-bottom: 0.4rem;
    display: block;
}

.popup-time {
    font-size: 0.68rem;
    color: rgba(234, 233, 239, 0.3);
}

/* ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   Note Form Overlay
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ */
.note-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: overlay-fade 0.2s ease-out;
}

.note-overlay[hidden] {
    display: none !important;
}

@keyframes overlay-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.note-card {
    width: 100%;
    max-width: 480px;
    box-sizing: border-box;
    background:
        linear-gradient(180deg, rgba(14, 18, 28, 0.98) 0%, rgba(8, 12, 20, 0.98) 100%);
    border: 1px solid rgba(145, 174, 203, 0.22);
    border-bottom: none;
    border-radius: 1.25rem 1.25rem 0 0;
    padding: 1.5rem 1.5rem 2.5rem;
    position: relative;
    max-height: 78vh;
    overflow-y: auto;
    box-shadow: 0 -18px 36px rgba(4, 8, 16, 0.55);
    animation: card-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes card-up {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2rem;
    height: 2rem;
    background: rgba(234, 233, 239, 0.06);
    border: 1px solid rgba(234, 233, 239, 0.13);
    color: rgba(234, 233, 239, 0.55);
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-family: 'Exo 2', sans-serif;
}

.close-btn:hover {
    background: rgba(234, 233, 239, 0.1);
    color: #eae9ef;
}

.note-card-title {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 600;
    color: #eae9ef;
    margin: 0 0 1.2rem;
    letter-spacing: 0.05em;
}

#plant-form {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

#plant-form input[type="text"],
#plant-form textarea {
    width: 100%;
    background: rgba(11, 16, 25, 0.84);
    border: 1px solid rgba(147, 176, 204, 0.24);
    border-radius: 0.5rem;
    padding: 0.7rem 0.9rem;
    color: rgba(232, 238, 246, 0.94);
    font-size: 0.92rem;
    font-family: 'Outfit', sans-serif;
    resize: none;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
}

#plant-form input[type="text"]::placeholder,
#plant-form textarea::placeholder {
    color: rgba(174, 197, 220, 0.58);
    font-family: 'Exo 2', sans-serif;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.72rem;
}

#plant-form input[type="text"]:focus,
#plant-form textarea:focus {
    outline: none;
    border-color: rgba(172, 205, 235, 0.6);
    box-shadow: 0 0 0 1px rgba(120, 170, 220, 0.18), 0 0 16px rgba(48, 88, 126, 0.25);
    background: rgba(12, 19, 29, 0.92);
}

#plant-form textarea.input-error {
    border-color: #7a1428;
}

.char-count {
    font-size: 0.74rem;
    color: rgba(234, 233, 239, 0.3);
    text-align: right;
    margin-top: -0.3rem;
}

/* GIF search area */
.gif-section {
    background: rgba(234, 233, 239, 0.03);
    border: 1px solid rgba(234, 233, 239, 0.09);
    border-radius: 0.5rem;
    padding: 0.7rem;
}

.gif-search-row {
    display: flex;
    gap: 0.5rem;
}

.gif-search-row input {
    flex: 1;
    background: rgba(11, 16, 25, 0.84);
    border: 1px solid rgba(147, 176, 204, 0.22);
    border-radius: 0.4rem;
    padding: 0.45rem 0.7rem;
    color: rgba(232, 238, 246, 0.94);
    font-size: 0.88rem;
    font-family: 'Outfit', sans-serif;
    appearance: none;
    -webkit-appearance: none;
}

.gif-search-row input::placeholder {
    color: rgba(174, 197, 220, 0.58);
    font-family: 'Exo 2', sans-serif;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.7rem;
}

.gif-search-row input:focus {
    outline: none;
    border-color: rgba(172, 205, 235, 0.55);
    box-shadow: 0 0 0 1px rgba(120, 170, 220, 0.16), 0 0 14px rgba(48, 88, 126, 0.22);
}

.btn-secondary {
    padding: 0.45rem 0.85rem;
    background: rgba(234, 233, 239, 0.08);
    border: 1px solid rgba(234, 233, 239, 0.16);
    color: rgba(234, 233, 239, 0.7);
    border-radius: 0.4rem;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: 'Exo 2', sans-serif;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn-secondary:hover { background: rgba(234, 233, 239, 0.12); color: #eae9ef; }

.gif-results {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
    margin-top: 0.55rem;
    max-height: 148px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(234, 233, 239, 0.2) transparent;
}

.gif-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 0.3rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: transform 0.15s ease, border-color 0.15s ease;
}

.gif-thumb:hover { transform: scale(1.05); border-color: rgba(234, 233, 239, 0.25); }

.gif-note {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 0.78rem;
    color: rgba(234, 233, 239, 0.4);
    padding: 0.5rem;
    margin: 0;
    line-height: 1.5;
}

.gif-note a { color: rgba(234, 233, 239, 0.65); text-decoration: underline; }

.gif-preview {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-top: 0.5rem;
}

.gif-preview img { max-height: 72px; border-radius: 0.3rem; display: block; }

.btn-clear {
    background: transparent;
    border: none;
    color: rgba(234, 233, 239, 0.35);
    cursor: pointer;
    font-size: 0.75rem;
    font-family: 'Outfit', sans-serif;
    padding: 0.25rem 0.4rem;
    transition: color 0.15s ease;
}
.btn-clear:hover { color: #eae9ef; }

/* Plant button */
.btn-plant {
    width: 100%;
    padding: 0.85rem;
    background: rgba(16, 22, 32, 0.62);
    border: 1px solid rgba(160, 188, 214, 0.36);
    color: rgba(231, 238, 246, 0.9);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: 'Exo 2', sans-serif;
    cursor: pointer;
    letter-spacing: 0.08em;
    transition: all 0.25s ease;
    appearance: none;
    -webkit-appearance: none;
}

.btn-plant:hover {
    background: rgba(21, 29, 42, 0.78);
    border-color: rgba(186, 213, 238, 0.62);
    color: #f3f7fb;
    box-shadow: 0 0 18px rgba(70, 112, 150, 0.22);
}

.btn-plant:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Screen-reader-only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Plant-a-star floating action button ── */
.plant-btn {
    position: fixed;
    bottom: calc(var(--mobile-nav-height, 4.25rem) + 0.7rem);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.65rem 1.4rem;
    background: rgba(12, 18, 27, 0.56);
    border: 1px solid rgba(160, 188, 214, 0.34);
    color: rgba(232, 239, 247, 0.88);
    border-radius: 999px;
    font-family: 'Exo 2', sans-serif;
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    cursor: pointer;
    z-index: 20;
    box-shadow: 0 4px 16px rgba(6, 10, 18, 0.35);
    transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease, color 0.25s ease, border-color 0.25s ease;
    white-space: nowrap;
    appearance: none;
    -webkit-appearance: none;
}

.plant-btn:hover {
    background: rgba(16, 24, 36, 0.76);
    border-color: rgba(186, 213, 238, 0.58);
    color: #f3f7fb;
    box-shadow: 0 6px 24px rgba(63, 102, 138, 0.2);
    transform: translateX(-50%) translateY(-2px);
}

.plant-btn.is-placing {
    background: rgba(234, 233, 239, 0.07);
    border-color: rgba(234, 233, 239, 0.22);
    box-shadow: none;
    color: rgba(234, 233, 239, 0.55);
}

.plant-btn.is-placing:hover {
    background: rgba(234, 233, 239, 0.11);
    transform: translateX(-50%) translateY(-2px);
    box-shadow: none;
}

.plant-btn-icon {
    font-size: 0.95rem;
    line-height: 1;
}

.plant-btn.is-placing .plant-btn-icon {
    display: inline-block;
    animation: spin-star 2s linear infinite;
}

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

/* ── Desktop adjustments ── */
@media (min-width: 900px) {
    .note-overlay {
        align-items: center;
    }

    .note-card {
        border: 1px solid rgba(234, 233, 239, 0.1);
        border-radius: 1rem;
        padding: 2rem;
        max-width: 420px;
        animation: card-scale 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    @keyframes card-scale {
        from { transform: scale(0.88); opacity: 0; }
        to   { transform: scale(1);    opacity: 1; }
    }

    .star-counter {
        top: 1.5rem;
        right: 2rem;
    }

    .plant-btn {
        bottom: 2rem;
    }
}

@media (max-width: 899px) {
    .note-star .star-popup,
    .note-star.popup-below .star-popup,
    .note-star.popup-left .star-popup,
    .note-star.popup-right .star-popup {
        display: none;
    }

    .note-star .star-popup::after,
    .note-star.popup-below .star-popup::after,
    .note-star.popup-left .star-popup::after,
    .note-star.popup-right .star-popup::after {
        display: none;
    }

    .mobile-note-overlay {
        position: fixed;
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 1rem;
        background: rgba(0, 0, 0, 0.52);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        z-index: 46;
    }

    .mobile-note-overlay[hidden] {
        display: none !important;
    }

    .mobile-note-card {
        width: min(320px, calc(100vw - 24px));
        max-height: min(70vh, 560px);
        overflow-y: auto;
        background: linear-gradient(180deg, rgba(18, 24, 34, 0.97) 0%, rgba(8, 12, 20, 0.97) 100%);
        border: 1px solid rgba(141, 171, 198, 0.34);
        border-radius: 0.8rem;
        padding: 1rem 1rem 0.9rem;
        box-shadow: 0 14px 30px rgba(2, 5, 11, 0.55), 0 0 0 1px rgba(120, 152, 183, 0.08) inset;
    }

    .mobile-note-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2rem;
        height: 2rem;
        margin-left: auto;
        margin-bottom: 0.55rem;
        border-radius: 999px;
        border: 1px solid rgba(234, 233, 239, 0.16);
        background: rgba(234, 233, 239, 0.06);
        color: rgba(234, 233, 239, 0.78);
        cursor: pointer;
    }

    .mobile-note-author {
        font-size: 0.68rem;
        font-family: 'Exo 2', sans-serif;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.12em;
        color: rgba(175, 202, 227, 0.88);
        margin: 0 0 0.35rem;
    }

    .mobile-note-message {
        font-family: 'Outfit', sans-serif;
        font-size: 0.92rem;
        color: rgba(230, 236, 244, 0.95);
        line-height: 1.55;
        margin: 0 0 0.6rem;
    }

    .mobile-note-gif {
        width: 100%;
        max-height: 180px;
        object-fit: cover;
        border-radius: 0.45rem;
        margin-bottom: 0.55rem;
        display: block;
    }

    .mobile-note-time {
        display: block;
        font-size: 0.7rem;
        color: rgba(234, 233, 239, 0.38);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .bg-star,
    .star-pulse,
    .field-hint,
    .note-card,
    .note-overlay {
        animation: none;
        transition: opacity 0.15s ease;
    }

    .star-popup {
        transition: opacity 0.15s ease;
    }
}

/* Star Notes: niche style for mini shell controls */
body[data-page="messages"] .mini-shell {
    left: 0.7rem;
    gap: 0.5rem;
}

body[data-page="messages"] .mini-btn {
    border-color: rgba(234, 233, 239, 0.14);
    background: rgba(10, 10, 14, 0.28);
    color: rgba(234, 233, 239, 0.8);
}

body[data-page="messages"] .mini-btn:hover,
body[data-page="messages"] .mini-btn:focus-visible {
    border-color: rgba(234, 233, 239, 0.28);
    background: rgba(20, 18, 28, 0.5);
}

body[data-page="messages"] .mini-btn-home {
    color: rgba(244, 244, 248, 0.86);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(12, 12, 16, 0.38);
}
