/* ============================================================
   THEME VARIABLES
   ============================================================ */
:root {
    --bg: #f5f5f5;
    --bg-alt: #fbfcfd;
    --text: #222;
    --text-soft: rgba(0,0,0,0.65);
    --card-bg: rgba(255,255,255,0.92);
    --card-bg-hover: rgba(255,255,255,0.96);
    --border: rgba(0,0,0,0.12);
    --menu-bg: rgba(255,255,255,0.96);
    --overlay-bg: rgba(255,255,255,0.55);
    --accent: #ff4f70;
    --accent-soft: rgba(255,79,112,0.25);
    --accent-glow: rgba(255,79,112,0.45);
    /* Image placeholder gradient (theme-aware) */
    --image-placeholder-gradient: linear-gradient(120deg, rgba(0,0,0,0.04), rgba(0,0,0,0.10));
    --image-placeholder-height: 220px;
}

/* Dark mode overrides */
body.dark-mode {
    --bg: #111;
    --bg-alt: #1c1c22;
    --text: #eee;
    --text-soft: rgba(255,255,255,0.65);
    --card-bg: rgba(26,26,30,0.72);
    --card-bg-hover: rgba(30,30,36,0.82);
    --border: rgba(255,255,255,0.06);
    --menu-bg: rgba(25,25,32,0.96);
    --overlay-bg: rgba(0,0,0,0.55);
    --accent: #ff6a86;
    --accent-soft: rgba(255,106,134,0.20);
    --accent-glow: rgba(255,106,134,0.30);
    --image-placeholder-gradient: linear-gradient(120deg, rgba(255,255,255,0.04), rgba(255,255,255,0.12));
}

body {
    margin: 0;
    padding: 40px;
    font-family: system-ui, sans-serif;
    background: linear-gradient(135deg, var(--bg), var(--bg-alt));
    color: var(--text);
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================================
   GLOBAL HEADER
   ============================================================ */
header.top-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0 20px 0;
    background: linear-gradient(135deg, var(--bg), var(--bg-alt));
    backdrop-filter: blur(14px);
}

/* Brand Home */
.brand-home {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 14px;
    transition: transform 0.25s ease, opacity 0.25s ease;
    background: transparent;
    border: none;
}

.brand-text {
    color: var(--text);
    transition: color 0.25s ease;
}

.brand-home.not-home {
    transform: scale(1.05);
}

.brand-aura {
    position: absolute;
    inset: 0;
    border-radius: 14px;
    background: radial-gradient(circle, var(--accent-soft), transparent 70%);
    opacity: 0;
    transform: scale(1);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
}

.brand-home.not-home .brand-aura {
    opacity: 0.9;
    transform: scale(1.4);
}

.brand-mark {
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: 2px solid var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--accent);
    transition: transform 0.25s ease, border-color 0.25s ease;
}

.brand-home.not-home .brand-mark {
    transform: scale(1.15);
}

/* ============================================================
   MENU TOGGLE BUTTON
   ============================================================ */
.menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    opacity: 0.9;
    transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

    .menu-toggle:hover {
        background: var(--card-bg-hover);
        transform: translateY(-1px);
        box-shadow: 0 8px 18px rgba(0,0,0,0.35);
    }

    .menu-toggle .menu-icon {
        display: inline-flex;
        flex-direction: column;
        gap: 3px;
    }

        .menu-toggle .menu-icon > span {
            display: block;
            width: 14px;
            height: 2px;
            border-radius: 999px;
            background: var(--text);
        }

/* ============================================================
   MAIN / FEED LAYOUT
   ============================================================ */
main {
    display: block;
}

section.feed {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
    transition: all 0.35s ease;
}

/* Desktop grid */
@media (min-width: 1000px) {
    section.feed {
        max-width: 1600px;
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
        gap: 28px 32px;
        padding: 10px 20px;
    }

    article.echo-card {
        animation: cascadeIn 0.45s ease both;
    }

    @keyframes cascadeIn {
        from {
            opacity: 0;
            transform: translateY(20px) scale(0.98);
        }

        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }
}

/* ============================================================
   ECHO CARD
   ============================================================ */
article.echo-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 26px;
    backdrop-filter: blur(10px);
    cursor: pointer;
    position: relative;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    transition: transform 0.28s cubic-bezier(.2,.9,.2,1), box-shadow 0.28s ease, border-color 0.28s ease;
}

    article.echo-card:hover {
        transform: translateY(-6px);
        box-shadow: 0 12px 30px rgba(0,0,0,0.10);
        border-color: rgba(0,0,0,0.10);
    }

    article.echo-card.last-viewed {
        border-left: 4px solid var(--accent);
        box-shadow: 0 0 0 2px var(--accent-soft), 0 6px 20px var(--accent-soft);
    }

.echo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.echo-title {
    margin: 0;
    font-size: 1.05rem;
}

.echo-meta {
    margin: 4px 0 6px 0;
    font-size: 0.85rem;
    color: var(--text-soft);
}

.visibility {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
}

    .badge.written {
        background: #4a90e2;
    }

    .badge.place {
        background: #50c878;
    }

    .badge.images {
        background: #d96df0;
    }

    .badge.noteworthy {
        background: #ff6b6b;
    }

    .badge.project {
        background: #f0a500;
    }

    .badge.link {
        background: #7bd3ff;
    }

    .badge.audio {
        /* a distinct green-teal for audio posts */
        background: linear-gradient(90deg, #38b48b, #6fe0a1);
    }

    .badge.link {
        /* more vivid purple-cyan for link posts to stand out */
        background: linear-gradient(90deg, #7b5cff, #4dd1ff);
    }

/* ============================================================
   ECHO META + TAGS
   ============================================================ */
.echo-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 6px 0 10px 0;
    font-size: 0.8rem;
    opacity: 0.75;
}

.echo-tags {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    opacity: 0.8;
}

.tag {
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(0,0,0,0.12);
    color: var(--text);
    font-size: 0.7rem;
}

/* ============================================================
   EXPANDED VIEW
   ============================================================ */
section.expanded-view {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(12px);
    z-index: 999;
    display: none;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

article.expanded-content {
    max-width: 860px;
    width: min(860px, 100%);
    max-height: min(90vh, 900px);
    background: var(--card-bg);
    color: var(--text);
    padding: 34px 34px 30px 34px;
    border-radius: 22px;
    border: 1px solid var(--border);
    position: relative;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08), 0 18px 46px rgba(0,0,0,0.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform-origin: top center;
    animation: expandCard 0.3s ease-out forwards;
    display: flex;
    flex-direction: column;
}

@media (max-width: 600px) {
    section.expanded-view {
        padding: 16px;
    }

    article.expanded-content {
        max-height: 90vh;
        padding: 26px 20px 24px 20px;
    }
}

.expanded-grab {
    width: 44px;
    height: 4px;
    border-radius: 999px;
    background: rgba(0,0,0,0.18);
    opacity: 0.45;
    margin: 0 auto 18px auto;
}

.expanded-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.expanded-kicker {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    opacity: 0.7;
}

.expanded-visibility-pill {
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--card-bg-hover);
    border: 1px solid var(--border);
    opacity: 0.9;
}

.expanded-title {
    margin: 0 0 6px 0;
    font-size: 1.7rem;
}

.expanded-meta {
    font-size: 0.85rem;
    opacity: 0.7;
    margin-bottom: 18px;
}

.expanded-date {
    white-space: nowrap;
}

.expanded-divider {
    height: 1px;
    background: var(--border);
    opacity: 0.8;
    margin-bottom: 20px;
}

/* ============================================================
   EXPANDED BODY — FIXED (NO FONT-SIZE ZERO)
   ============================================================ */
.expanded-body {
    font-size: 0.95rem;
    line-height: 1.6;
}

    .expanded-body p {
        margin: 0 0 1em 0;
    }

    /* Anchor/link rules in expanded content
   - Force anchors to behave like inline text (no baseline shifting)
   - Use a transparent border for hover transitions without affecting layout
*/
    .expanded-body a {
        color: var(--accent);
        text-decoration: none;
        border-bottom: 1px solid transparent; /* transparent border avoids subpixel baseline shift */
        transition: border-color 0.2s ease, color 0.12s ease;
        display: inline; /* ensure inline flow */
        vertical-align: baseline; /* align to text baseline explicitly */
        line-height: inherit; /* inherit surrounding line-height */
    }

        /* Hover/focus state for accessibility */
        .expanded-body a:hover,
        .expanded-body a:focus {
            border-bottom-color: var(--accent);
            outline: none;
        }

        /* Accessible focus-visible */
        .expanded-body a:focus-visible {
            box-shadow: 0 0 0 3px var(--accent-soft);
        }

        /* Keep anchor children from changing line-height unexpectedly */
        .expanded-body a * {
            line-height: inherit;
        }

        .expanded-body a:hover {
            border-bottom-color: var(--accent);
        }

/* ============================================================
   COMMENTS PANEL (EXPANDED VIEW)
   ============================================================ */
.comments-panel {
    margin-top: 20px;
    border-top: 1px solid var(--border);
    padding-top: 18px;
    display: block;
}

.comments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.comments-header h3 {
    margin: 0;
    font-size: 1rem;
}

.comment-toggle-btn {
    background: var(--card-bg-hover);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
}

body.dark-mode .comment-toggle-btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text);
}

/* ============================================================
   COMMENT LIST + COMMENT BLOCK
   ============================================================ */
.comments-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}

.comment {
    padding: 12px;
    border-radius: 10px;
    background: rgba(0,0,0,0.03);
    border: 1px solid rgba(0,0,0,0.04);
}

.comment .meta {
    font-size: 0.8rem;
    color: var(--text-soft);
    margin-bottom: 6px;
}

.comment .content {
    font-size: 0.92rem;
}

/* ============================================================
   TOP‑LEVEL COMMENT FORM
   ============================================================ */
.comment-form {
    display: none;
    margin-top: 8px;
    gap: 8px;
}

.comment-form.visible {
    display: flex;
    flex-direction: column;
}

.comment-form textarea {
    width: 100%;
    min-height: 86px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    resize: vertical;
    background: var(--card-bg);
    color: var(--text);
}

.comment-form .comment-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.comment-form button {
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
}

.comment-form .submit {
    background: var(--accent);
    color: white;
}

/* ============================================================
   REPLY FORM
   ============================================================ */

/* Reply button: make it look like an inline action */
.reply-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    font-size: 0.85rem;
    cursor: pointer;
}

.reply-btn:hover {
    text-decoration: underline;
}

/* Reply form container */
.reply-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

/* Reply textarea */
.reply-form textarea {
    width: 100%;
    max-width: 100%;
    min-height: 70px;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--border);
    resize: vertical;
    background: var(--card-bg);
    color: var(--text);
    box-sizing: border-box;
}

/* Buttons row (Cancel + Post Reply) */
.reply-buttons {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* Buttons: natural width, no stretching */
.reply-buttons button {
    width: auto;
    flex: 0 0 auto;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
}

/* Submit inherits your global accent button style */
.reply-submit {
    background: var(--accent);
    color: white;
    border: none;
}

/* Cancel inherits your global cancel style */
.reply-cancel {
    background: var(--card-bg-hover);
    border: 1px solid var(--border);
    color: var(--text);
}


/* ============================================================
   SKELETON
   ============================================================ */
.comment-skeleton {
    height: 68px;
    border-radius: 10px;
    background: var(--image-placeholder-gradient);
    animation: echoImagePulse 1.4s ease-in-out infinite;
}

/* Reply form buttons: same line, fixed width */
.comments-panel .reply-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comments-panel .reply-form-buttons {
    display: flex;
    gap: 8px;
}

.comments-panel .reply-form-buttons button {
    width: 25%;
    min-width: 100px; /* prevents tiny buttons on mobile */
}


/* ============================================================
   EXPANDED VIEW ANIMATIONS
   ============================================================ */
@keyframes expandCard {
    from {
        transform: scale(0.92) translateY(20px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes collapseCard {
    0% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }

    40% {
        transform: scale(0.97) translateY(20px) rotateX(4deg);
        opacity: 0.85;
    }

    100% {
        transform: scale(0.92) translateY(120px) rotateX(12deg);
        opacity: 0;
    }
}

/* ============================================================
   FLOATING CLOSE BUTTON
   ============================================================ */
.expanded-close {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0,0,0,0.55);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.2s ease, background 0.25s ease;
    z-index: 2000;
}

body.dark-mode .expanded-close {
    background: rgba(255,255,255,0.18);
    color: white;
}

.expanded-close.visible {
    opacity: 1;
    pointer-events: auto;
}

.expanded-close:hover {
    transform: scale(1.1);
    background: rgba(255,255,255,0.28);
}

/* ============================================================
   CONTENT PANEL
   ============================================================ */
section.content-panel {
    max-width: 780px;
    margin: 20px auto 40px auto;
    padding: 26px;
    background: var(--card-bg);
    border-radius: 18px;
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
    display: none;
}
/* ============================================================
   MENU OVERLAY
   ============================================================ */
nav.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(18px) saturate(140%);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    opacity: 0;
    transition: opacity 0.25s ease;
}

    nav.menu-overlay.visible {
        display: flex;
        opacity: 1;
    }

.menu-panel {
    width: min(420px, 92vw);
    background: linear-gradient(135deg, rgba(255,255,255,0.22), rgba(255,255,255,0.08));
    border-radius: 22px;
    border: 1px solid rgba(255,255,255,0.25);
    box-shadow: 0 12px 40px rgba(0,0,0,0.45), inset 0 0 40px rgba(255,255,255,0.08);
    padding: 26px 26px 20px 26px;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    transition: transform 0.28s ease, opacity 0.28s ease;
}

nav.menu-overlay.visible .menu-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.menu-title {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    opacity: 0.85;
    font-weight: 600;
}

.menu-close {
    border: none;
    background: rgba(255,255,255,0.18);
    color: var(--text);
    cursor: pointer;
    font-size: 1rem;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
    transition: background 0.2s ease, transform 0.2s ease;
}

    .menu-close:hover {
        background: rgba(255,255,255,0.32);
        transform: scale(1.08);
    }

.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

    .menu-list li {
        position: relative;
        padding: 12px 14px 12px 18px;
        border-radius: 12px;
        font-size: 0.95rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 10px;
        background: rgba(255,255,255,0.06);
        border: 1px solid rgba(255,255,255,0.08);
        transition: background 0.22s ease, transform 0.22s ease, border-color 0.22s ease;
    }

        .menu-list li::before {
            content: "";
            position: absolute;
            left: 0;
            top: 8px;
            bottom: 8px;
            width: 4px;
            border-radius: 4px;
            background: var(--accent);
            opacity: 0;
            transform: translateX(-6px);
            transition: opacity 0.22s ease, transform 0.22s ease;
        }

        .menu-list li:hover::before {
            opacity: 1;
            transform: translateX(0);
        }

        .menu-list li:hover {
            background: rgba(255,255,255,0.18);
            border-color: rgba(255,255,255,0.22);
            transform: translateX(4px);
        }

        .menu-list li:hover {
            background: rgba(255,255,255,0.18);
            border-color: rgba(255,255,255,0.22);
            transform: translateX(4px);
        }

/* ============================================================
   LIGHT MODE MENU OVERRIDES
   ============================================================ */
body:not(.dark-mode) nav.menu-overlay {
    background: rgba(255,255,255,0.45);
    backdrop-filter: blur(18px) saturate(160%);
}

body:not(.dark-mode) .menu-panel {
    background: linear-gradient(135deg, rgba(255,255,255,0.55), rgba(255,255,255,0.28));
    border: 1px solid rgba(255,255,255,0.55);
    box-shadow: 0 12px 40px rgba(0,0,0,0.25), inset 0 0 40px rgba(255,255,255,0.18);
}

body:not(.dark-mode) .menu-list li {
    background: rgba(255,255,255,0.55);
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 2px 4px rgba(0,0,0,0.06), 0 4px 10px rgba(0,0,0,0.04);
}

    body:not(.dark-mode) .menu-list li:hover {
        background: rgba(255,255,255,0.75);
        border-color: rgba(0,0,0,0.12);
    }

body:not(.dark-mode) .menu-close {
    background: rgba(255,255,255,0.35);
}

    body:not(.dark-mode) .menu-close:hover {
        background: rgba(255,255,255,0.55);
    }

/* ============================================================
   MOBILE RIPPLE EFFECT
   ============================================================ */
@media (hover: none) {
    .menu-list li {
        overflow: hidden;
    }

        .menu-list li:active::after {
            content: "";
            position: absolute;
            left: 50%;
            top: 50%;
            width: 0;
            height: 0;
            background: var(--accent-soft);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            animation: ripple 0.45s ease-out forwards;
        }

    @keyframes ripple {
        from {
            width: 0;
            height: 0;
            opacity: 0.45;
        }

        to {
            width: 260px;
            height: 260px;
            opacity: 0;
        }
    }
}

/* ============================================================
   LOGIN MODAL
   ============================================================ */
section.login-modal {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    opacity: 0;
    transition: opacity 0.25s ease;
}

    section.login-modal.visible {
        display: flex;
        opacity: 1;
    }

.login-box {
    width: min(380px, 90vw);
    background: var(--menu-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    animation: fadeIn 0.3s ease;
}

    .login-box h2 {
        margin-top: 0;
        margin-bottom: 18px;
        font-size: 1.2rem;
        text-align: center;
    }

    .login-box input {
        width: 100%;
        padding: 10px 12px;
        margin-bottom: 12px;
        border-radius: 10px;
        border: 1px solid var(--border);
        background: var(--card-bg);
        color: var(--text);
        font-size: 0.9rem;
    }

    .login-box button {
        width: 100%;
        padding: 10px 12px;
        border-radius: 10px;
        border: none;
        background: #4a90e2;
        color: white;
        font-size: 0.95rem;
        cursor: pointer;
        margin-top: 6px;
        transition: background 0.2s ease;
    }

        .login-box button:hover {
            background: #6ab0ff;
        }

    .login-box .cancel {
        background: #666;
    }

        .login-box .cancel:hover {
            background: #888;
        }

/* ============================================================
   SCROLL TO TOP BUTTON
   ============================================================ */
#scrollTopBtn {
    position: fixed;
    bottom: 40px;
    right: 40px;
    background: #4a90e2;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.2s ease;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    display: flex;
}

    #scrollTopBtn.visible {
        opacity: 1;
        pointer-events: auto;
    }

    #scrollTopBtn:hover {
        background: #6ab0ff;
        transform: translateY(-3px);
    }

/* ============================================================
   SIMPLE FADE-IN
   ============================================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
/* ============================================================
   INLINE ECHO IMAGES + THUMBNAILS
   ============================================================ */
/* Ensure images always break onto their own line */
.echo-image {
    display: block;
    width: 100%;
    margin: 12px 0;
    border-radius: 14px;
    overflow: hidden;
    position: relative;
    clear: both; /* force image to its own line regardless of surrounding markup */
    box-sizing: border-box;
}

.echo-image-placeholder {
    width: 100%;
    height: var(--image-placeholder-height);
    border-radius: 14px;
    background: var(--image-placeholder-gradient);
    animation: echoImagePulse 1.4s ease-in-out infinite;
}

.echo-image img {
    display: block;
    width: 100%;
    max-height: 260px;
    object-fit: cover;
    border-radius: 14px;
    opacity: 0;
    transform: scale(0.98);
    transition: opacity 220ms ease-out, transform 220ms ease-out;
    cursor: zoom-in;
}

    .echo-image img.echo-image-loaded {
        opacity: 1;
        transform: scale(1);
    }
/* ============================================================
   GALLERY: corralled images placed after text
   ============================================================ */
.expanded-images {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
}

/* desktop: three-column thumbnails in gallery */
@media (min-width: 900px) {
    .expanded-images .echo-image {
        flex: 0 0 calc((100% - 24px) / 3);
        width: calc((100% - 24px) / 3);
        margin: 0;
        aspect-ratio: 4 / 3;
        overflow: hidden;
    }
}

/* mobile: full width */
@media (max-width: 899px) {
    .expanded-images .echo-image {
        flex: 1 1 100%;
        width: 100%;
        margin: 12px 0;
    }
}

/* Ensure images inside gallery behave */
.expanded-images .echo-image img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 14px;
}

/* Make sure any inline images inside text are rendered as block and break lines (extra safety) */
.expanded-body img,
.expanded-body p img {
    display: block;
    width: 100%;
    margin: 12px 0;
}

/* ============================================================
   IMAGE VIEWER — FORCED, ROBUST RULES (fix centering + stacking)
   - these rules ensure the overlay cannot be clipped/offset
   ============================================================ */
.image-viewer-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    min-height: calc(var(--vh, 1vh) * 100) !important;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2147483647; /* very high to beat other stacking contexts */
    overflow: hidden;
    touch-action: none;
    -webkit-overflow-scrolling: auto;
    transform: none !important; /* ignore ancestor transforms */
    contain: strict;
}

    .image-viewer-overlay.active {
        display: flex !important;
        pointer-events: auto !important;
    }

/* backdrop */
.image-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.82);
    backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 220ms ease-out;
}

.image-viewer-overlay.active .image-viewer-backdrop {
    opacity: 1;
}

/* center frame */
.image-viewer-frame {
    position: relative !important;
    width: 100%;
    height: 100%;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden;
    touch-action: none;
}

/* image element */
.image-viewer-img {
    position: relative !important;
    max-width: calc(100vw - 32px) !important;
    max-height: calc(100vh - 32px) !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    transform-origin: center center !important;
    touch-action: none;
    transition: transform 0.05s linear, opacity 0.05s linear !important;
    display: block !important;
    margin: 0 auto !important;
}

/* ============================================================
   REST OF CSS (unchanged)
   ============================================================ */

/* iOS momentum scrolling fix */
.image-viewer-frame,
.expanded-content {
    -webkit-overflow-scrolling: touch;
}

/* Prevent text selection during drag interactions */
.image-viewer-frame,
.expanded-view,
.expanded-content {
    user-select: none;
    -webkit-user-select: none;
}

/* LEGACY BACK BUTTON */
#floatingBack {
    display: none !important;
}

/* Safety: make sure expanded-body text visible */
.expanded-body,
.expanded-body * {
    font-size: inherit;
    color: inherit;
    line-height: inherit;
}

/* small responsive tweaks */
@media (max-width: 420px) {
    .meta-right {
        gap: 8px;
    }

    .echo-title {
        font-size: 1rem;
    }
}

/* END */

/* ============================================================
   ADDITIONS: portal / view-type styles (scoped, additive)
   - These are intentionally minimal and isolated so existing
     card and panel styles are unchanged.
   ============================================================ */

/* Portal card mode: keep echo-card visuals but center contentPanel content */
.content-panel.portal-card-mode {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 28px;
}

/* Small tweak for the inlined portal-card (keeps existing .echo-card intact) */
.portal-card {
    max-width: 640px;
    width: 100%;
    animation: fadeIn 0.28s ease;
}

/* Panel mode: larger comfortable content area (does not change .content-panel core rules) */
.content-panel.portal-panel-mode {
    max-width: 960px;
    margin: 20px auto 40px auto;
    padding: 30px;
    overflow-y: auto;
    animation: fadeIn 0.22s ease;
}

/* Portal (dramatic) mode: add dimming and a subtle rift visual via box-shadow and overlay */
body.portal-open {
    /* dim the global background slightly while portal is open */
    transition: background 0.25s ease;
}

.content-panel.portal-portal-mode {
    position: relative;
    z-index: 1300;
    max-width: 1100px;
    margin: 26px auto;
    padding: 36px;
    border-radius: 18px;
    box-shadow: 0 18px 46px rgba(0,0,0,0.45), 0 0 120px rgba(255,255,255,0.02) inset;
    transform-origin: center top;
    animation: portalOpen 420ms cubic-bezier(.2,.9,.28,1) forwards;
}

/* subtle "dim" backdrop while portal content is visible */
body.portal-open::before {
    content: "";
    pointer-events: none;
    position: fixed;
    inset: 0;
    background: rgba(6,10,15,0.36);
    backdrop-filter: blur(6px) saturate(120%);
    z-index: 1200;
    opacity: 1;
}

/* small portal opening animation */
@keyframes portalOpen {
    from {
        transform: translateY(12px) scale(0.98);
        opacity: 0;
        filter: blur(2px);
    }

    to {
        transform: translateY(0) scale(1);
        opacity: 1;
        filter: blur(0);
    }
}

/* keep these additions small and additive — existing card and panel rules remain unchanged */
/* END OF ADDITIONS */

/* ============================================================
   ADDITIONS: badge color for audio + subtle pulse for last-viewed
   - Append these lines to the end of your existing style.css
   - Scoped and additive; does not replace base card rules
   ============================================================ */

.badge.audio {
    /* a distinct green-teal for audio posts */
    background: linear-gradient(90deg, #00E6A8 0%, #00A57A 100%) !important;
    color: #001f15 !important;
    box-shadow: 0 6px 18px rgba(0,90,70,0.12) !important;
    border: 1px solid rgba(0,140,100,0.08) !important;
}

/* Dark mode variant for audio pill */
body.dark-mode .badge.audio {
    background: linear-gradient(90deg, #00B689 0%, #007A58 100%) !important;
    color: #e6fff4 !important;
    box-shadow: 0 6px 22px rgba(0,0,0,0.6) !important;
}

/* last-viewed pulsing accent (subtle, additive) */
@keyframes lastViewedPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255,79,112,0.12), 0 6px 20px rgba(255,79,112,0.06);
    }

    50% {
        box-shadow: 0 0 18px 6px rgba(255,79,112,0.06), 0 10px 30px rgba(255,79,112,0.08);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255,79,112,0.12), 0 6px 20px rgba(255,79,112,0.06);
    }
}

/* apply pulse only lightly so it remains tasteful */
article.echo-card.last-viewed {
    animation: lastViewedPulse 2.4s ease-in-out infinite;
}

/* ===== Minimal additions/overrides for portal close button + stronger audio pill ===== */

/* Prominent floating close on portal views — visible and accessible */
.content-panel.portal-portal-mode {
    position: relative; /* ensure absolute-positioned close button is within panel */
}

    .content-panel.portal-portal-mode .portal-float-close {
        position: absolute;
        top: 12px;
        right: 12px;
        z-index: 1400;
        border: none;
        background: linear-gradient(90deg, var(--accent), var(--accent-glow));
        color: #fff;
        padding: 8px 12px;
        border-radius: 10px;
        font-weight: 700;
        font-size: 0.95rem;
        cursor: pointer;
        box-shadow: 0 10px 30px rgba(0,0,0,0.45), 0 0 18px var(--accent-soft);
        transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
    }

        .content-panel.portal-portal-mode .portal-float-close:focus,
        .content-panel.portal-portal-mode .portal-float-close:focus-visible {
            outline: none;
            box-shadow: 0 12px 36px rgba(0,0,0,0.5), 0 0 0 4px var(--accent-soft);
            transform: translateY(-2px) scale(1.02);
        }

/* Ensure mobile hit target is larger */
@media (max-width: 899px) {
    .content-panel.portal-portal-mode .portal-float-close {
        padding: 10px 14px;
        border-radius: 12px;
    }
}

/* Portal loader overlay (cancellable) */
.portal-loader-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
    background: rgba(6,10,15,0.36);
    backdrop-filter: blur(6px);
    pointer-events: auto;
}

.portal-loader-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    color: var(--text);
    padding: 18px 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 12px 36px rgba(0,0,0,0.45);
    min-width: 220px;
    max-width: 90vw;
    text-align: center;
}

.portal-loader-spinner {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 4px solid rgba(0,0,0,0.06);
    border-top-color: var(--accent);
    animation: portalSpin 820ms linear infinite;
}

@keyframes portalSpin {
    to { transform: rotate(360deg); }
}

.portal-loader-text {
    font-size: 0.95rem;
    color: var(--text-soft);
}

.portal-loader-cancel {
    margin-top: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-weight: 600;
}

.portal-loader-cancel:hover {
    text-decoration: underline;
}

.portal-loader-overlay {
    opacity: 1;
    transition: opacity 200ms ease;
}

.portal-loader-overlay.portal-loader-fade-out {
    opacity: 0;
}

.portal-loader-text.portal-loader-ready {
    font-weight: 600;
    /* optional: color change or subtle glow */
}

/* ============================================================
   ACCESS CONTROL PANEL — THEME-AWARE (LIGHT + DARK)
   ============================================================ */

.access-list-panel {
    margin: 18px 0 24px 0;
}

/* Outer container */
.access-list-box {
    background: var(--card-bg, #f8f8fb);
    border: 1px solid var(--border, #e3e3ee);
    border-radius: 14px;
    padding: 0;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Header row with toggle */
.access-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: var(--card-bg-hover, #f0f0f7);
    border-bottom: 1px solid var(--border, #e3e3ee);
}

.access-list-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text, #444);
    letter-spacing: 0.2px;
}

/* Toggle button */
.access-toggle {
    background: none;
    border: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-soft, #555);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s ease;
}

.access-toggle:hover {
    background: rgba(255,255,255,0.08);
}

/* Collapsible content */
.access-list-content {
    padding: 16px 18px 20px 18px;
    display: block;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-3px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Two-column layout */
.access-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.access-col {
    display: flex;
    flex-direction: column;
}

/* Labels */
.access-list-label {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.access-list-label.allow {
    color: #2a7a2a;
}

.access-list-label.deny {
    color: #b02a2a;
}

/* Pills container */
.access-list-values {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Pills (unchanged per your request) */
.access-pill {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    border: 1px solid transparent;
}

.allow-pill {
    background: #e6f7e6;
    color: #1d6b1d;
    border-color: #cceccc;
}

.deny-pill {
    background: #fbe5e5;
    color: #8a1f1f;
    border-color: #f1caca;
}

/* Empty state text */
.access-empty,
.access-empty-state {
    font-size: 0.85rem;
    opacity: 0.65;
    line-height: 1.4;
    color: var(--text-soft, #444);
}

.access-empty-state strong {
    font-weight: 600;
}

/* Mobile responsiveness */
@media (max-width: 600px) {
    .access-columns {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}
