/* Fixed black/red theme (no light mode) — matches exceptionerror.com's login page. */
:root {
    --bg: #000000;
    --card: #141414;
    --field: #1a1a1a;
    --text: #f2f2f2;
    --muted: #9a7a7a;
    --border: #3a1414;
    --accent: #ff0000;
    --accent-dark: #8b0000;
    --accent-text: #ffffff;
    --pill-text: #ffcccc;
    --error: #ff6b6b;
}

* { box-sizing: border-box; }

html { font-size: 17px; } /* everything sized in rem scales from here */

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    padding-top: 52px; /* space for the fixed .topbar */
}

.wrap {
    max-width: 620px;
    margin: 0 auto;
    padding: 24px 16px 96px;
}

h1 { font-size: 1.5rem; margin: 4px 0 20px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
}

/* ---- forms ---- */
input, textarea {
    width: 100%;
    padding: 9px 11px;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--field);
    color: var(--text);
    font: inherit;
    resize: vertical;
}

/* Single-line auth fields get the reference site's pill shape. */
.field input {
    border-radius: 24px;
    padding: 11px 18px;
}

input:focus, textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: transparent;
}

.btn {
    padding: 9px 22px;
    border: 2px solid var(--accent);
    border-radius: 30px;
    background: var(--field);
    color: var(--pill-text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s, color .2s, box-shadow .2s, transform .2s;
}
.btn:hover:not(:disabled) {
    background: var(--accent);
    color: var(--accent-text);
    box-shadow: 0 4px 15px rgba(255, 0, 0, .4);
    transform: translateY(-1px);
}

.btn:disabled { opacity: .5; cursor: default; }

.new-post-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.file-label {
    cursor: pointer;
    color: var(--muted);
    font-weight: 600;
    font-size: .9rem;
    user-select: none;
}
.file-label:hover { color: var(--accent); }

.image-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.preview-tile {
    position: relative;
    width: 84px;
    height: 84px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}
.preview-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}
.preview-remove:hover { background: var(--accent); }

/* ---- posts ---- */
.post-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    display: grid;
    place-items: center;
    font-weight: 700;
    flex-shrink: 0;
}

.author { font-weight: 600; }
.time { color: var(--muted); font-size: .85rem; }

.post-body {
    margin: 0 0 10px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-weight: 500;
}

.post-image {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: cover;
    border-radius: 10px;
    margin: 0 0 10px;
    background: var(--bg);
}

/* 2+ images: a cropped grid; each tile links to the full-size original. */
.post-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 4px;
    margin: 0 0 10px;
    border-radius: 10px;
    overflow: hidden;
}
.post-image-tile { display: block; aspect-ratio: 1 / 1; background: var(--bg); }
.post-image-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

.post-actions {
    display: flex;
    align-items: center;
    gap: 18px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.link-btn {
    border: none;
    background: none;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}
.link-btn:hover { color: var(--accent); }
.link-btn.small { font-size: .82rem; }

/* ---- likes / dislikes ---- */
.votes {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.vote-btn {
    border: none;
    background: none;
    cursor: pointer;
    color: var(--muted);
    font-size: .8rem;
    line-height: 1;
    padding: 4px 5px;
    border-radius: 6px;
}
.vote-btn:hover { background: var(--border); }
.vote-btn:disabled { cursor: default; opacity: .5; }
.vote-btn.up.active { color: #4ade80; }
.vote-btn.down.active { color: var(--accent); }

.vote-count {
    font-size: .85rem;
    color: var(--muted);
    min-width: 1ch;
    text-align: left;
}

/* ---- comments ---- */
.comments { margin-top: 12px; }

.comment-list { list-style: none; margin: 0 0 12px; padding: 0; }

.comment {
    border-top: 1px solid var(--border);
    padding: 10px 0 6px;
}

.comment-meta { font-size: .85rem; }
.c-author { font-weight: 600; }
.c-body { margin: 3px 0 6px; white-space: pre-wrap; word-wrap: break-word; font-weight: 500; }

.comment-image {
    display: block;
    max-width: 100%;
    max-height: 320px;
    object-fit: contain;
    border-radius: 8px;
    margin: 4px 0 8px;
    background: var(--bg);
}

/* 2+ images on a comment: a compact grid, smaller than a post's. */
.comment-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 4px;
    max-width: 320px;
    margin: 4px 0 8px;
    border-radius: 8px;
    overflow: hidden;
}
.comment-image-tile { display: block; aspect-ratio: 1 / 1; background: var(--bg); }
.comment-image-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* image add/remove row inside a post's edit box */
.image-edit-row { margin-bottom: 8px; }
.image-edit-row .image-previews { margin-bottom: 8px; }
.file-label.small { font-size: .8rem; }

.comment-actions {
    display: flex;
    align-items: center;
    gap: 14px;
}


/* nested replies: a threading line + a little indent, capped by JS at depth 4 */
.comment-list.replies {
    margin: 0 0 0 14px;
    padding-left: 12px;
    border-left: 2px solid var(--border);
}
.comment-list.replies .comment:first-child { border-top: none; padding-top: 4px; }

.comment-form {
    margin-top: 8px;
}
.form-controls {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* ---- misc ---- */
.status { text-align: center; color: var(--muted); min-height: 1.2em; }
.muted { color: var(--muted); }
.error { color: var(--error); }
#sentinel { height: 1px; }

/* ---- top bar (fixed, full-width) ---- */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 20px;
    background: #000;
    border-bottom: 1px solid var(--accent-dark);
    z-index: 1000;
}
.brand { font-size: 1.2rem; font-weight: 900; color: var(--accent); text-decoration: none; letter-spacing: .01em; }
.authbox { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.who { font-weight: 900; color: var(--accent); text-decoration: none; }
.who:hover { color: #fff; }
.author-link { color: inherit; text-decoration: none; }
.author-link:hover { text-decoration: underline; }

.authbox .link-btn {
    color: var(--pill-text);
    border: 1px solid var(--accent);
    border-radius: 20px;
    padding: 6px 14px;
    font-weight: 600;
}
.authbox .link-btn:hover { background: var(--accent-dark); color: #fff; }

.btn.small { padding: 5px 12px; font-size: .85rem; }
.ok { color: #4ade80; }
.tag { color: var(--muted); font-size: .8rem; text-decoration: none; }
a.tag:hover { color: var(--accent); text-decoration: underline; }

.banner {
    background: var(--card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: .9rem;
}

/* ---- auth: modal ---- */
#auth-modal {
    position: relative;
    width: min(26rem, calc(100vw - 32px));
    border: 2px solid var(--accent);
    border-radius: 16px;
    padding: 22px;
    background: #0d0d0d;
    color: var(--text);
    box-shadow: 0 0 30px rgba(255, 0, 0, .3);
}
#auth-modal::backdrop { background: rgba(0, 0, 0, .7); }

#util-modal {
    position: relative;
    width: min(32rem, calc(100vw - 32px));
    border: 2px solid var(--accent);
    border-radius: 16px;
    padding: 22px;
    background: #0d0d0d;
    color: var(--text);
    box-shadow: 0 0 30px rgba(255, 0, 0, .3);
}
#util-modal::backdrop { background: rgba(0, 0, 0, .7); }
#util-modal-body h2 {
    margin: 0 0 14px;
    padding: 0 34px 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 1.2rem;
    font-weight: 700;
}

/* Close button sits in the corner so the title can start at the top-left. */
.modal-x { position: absolute; top: 14px; right: 14px; margin: 0; z-index: 1; }
.modal-x button {
    border: none; background: none; color: var(--muted);
    font-size: 2rem; line-height: 1; cursor: pointer;
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form h2 { margin: 0; padding-right: 34px; font-size: 1.2rem; }

.btn-google {
    text-align: center;
    text-decoration: none;
    border-color: var(--border);
    background: var(--field);
    color: var(--pill-text);
}
.btn.btn-google:hover {
    background: var(--field);
    color: var(--accent);
    box-shadow: none;
    border-color: var(--accent);
}
.auth-divider {
    margin: -4px 0;
    text-align: center;
    color: var(--muted);
    font-size: .8rem;
}
.google-btn-wrap { display: flex; flex-direction: column; gap: 6px; }
.google-btn-wrap .muted { text-align: center; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; }
.field input { margin: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.check input { width: auto; margin: 0; }

.acct-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border);
    padding-top: 14px;
    margin-top: 14px;
}
.acct-section h3 { margin: 0; font-size: .95rem; }
.acct-section .btn { align-self: flex-start; }
.acct-section.danger h3 { color: var(--error); }

/* ---- owner edit / delete ---- */
.post-head { position: relative; }
.owner-menu { display: flex; gap: 10px; margin-left: auto; }
.link-btn.danger { color: var(--error); }
.link-btn.danger:hover { color: #b91c1c; }

.edit-box { margin: 4px 0 10px; }
.edit-area { width: 100%; margin-bottom: 8px; }

.comment.is-deleted > .c-body { font-style: italic; }

/* ---- following sidebar ---- */
.layout {
    display: flex;
    gap: 28px;
    justify-content: center;
    align-items: flex-start;
}
.sidebar {
    /* A pane like the chat panes: card background, border, rounded, scrolls inside itself. Width is the
       user-resizable --w-sidebar (see layout.js). */
    box-sizing: border-box;
    width: var(--w-sidebar, 220px);
    max-width: 30vw;
    flex-shrink: 0;
    order: 1;
    position: sticky;
    top: 76px;
    margin: 0;
    padding: 14px;
    height: calc(100vh - 92px); height: calc(100dvh - 92px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.sidebar-title { font-size: 1rem; margin: 0 0 10px; }

.follow-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 7px;
    color: var(--text);
    text-decoration: none;
    font-size: .9rem;
}
.follow-row:hover { background: var(--card); }

.follow-badge {
    background: var(--accent);
    color: var(--accent-text);
    font-size: .72rem;
    font-weight: 700;
    min-width: 1.5em;
    height: 1.5em;
    padding: 0 .35em;
    border-radius: 1em;
    display: grid;
    place-items: center;
}

.profile-head {
    display: flex;
    align-items: center;
    gap: 12px;
}
/* Title pinned left; share / tags / action buttons cluster on the right. */
.profile-head h2 { margin: 0 auto 0 0; font-size: 1.2rem; }
.btn.small.is-following {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

/* ---- top bar: menu button (phones only) ---- */
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: none;
    color: var(--pill-text);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}
.menu-btn:active { background: var(--accent-dark); }
.drawer-backdrop { display: none; }

/* Tablet / phone: the sidebar becomes a slide-out drawer opened from the ☰ button,
   so the feed comes first instead of being pushed down by the friends/groups lists. */
@media (max-width: 900px) {
    .layout { display: block; }
    .menu-btn:not([hidden]) { display: inline-flex; }

    .sidebar {
        position: fixed;
        top: 52px; left: 0; bottom: 0;
        width: min(84vw, 320px);
        margin: 0;
        max-width: none;
        height: auto;
        padding: 16px 16px 28px;
        overflow-y: auto;
        overscroll-behavior: contain;
        background: #0a0a0a;
        border: 0;
        border-right: 1px solid var(--accent-dark);
        border-radius: 0;
        transform: translateX(-102%);
        visibility: hidden;
        transition: transform .22s ease, visibility 0s linear .22s;
        z-index: 900;
    }
    body.drawer-open .sidebar {
        transform: none;
        visibility: visible;
        transition: transform .22s ease, visibility 0s;
    }
    body.drawer-open { overflow: hidden; }

    .drawer-backdrop {
        display: block;
        position: fixed;
        top: 52px; right: 0; bottom: 0; left: 0;
        background: rgba(0, 0, 0, .6);
        z-index: 850;
    }
    .drawer-backdrop[hidden] { display: none; }

    .install-box:not([hidden]) { display: block; }
}

/* ---- sidebar: friends / following ---- */
.sidebar-section {
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.sidebar-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.sidebar-head .sidebar-title { margin: 0; }

.add-btn {
    margin-left: auto;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid var(--accent);
    border-radius: 50%;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.add-btn span { transform: translateY(-1px); }
.add-btn:hover { background: var(--accent); color: #fff; }

.inline-add {
    display: flex;
    gap: 6px;
    flex: 1 1 100%; /* own row under the title whenever it doesn't fit beside it */
}
.inline-add input {
    flex: 1;
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 6px 10px;
    font-size: .82rem;
}
.inline-add button { flex-shrink: 0; }
.tiny-check { flex-shrink: 0; font-size: .72rem; color: var(--muted); gap: 4px; }
.group-add-form { flex-wrap: wrap; }
.group-add-actions { display: flex; gap: 8px; flex: 1 1 100%; }

.modal-divider { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.group-discovery { display: flex; flex-direction: column; gap: 8px; }
.group-discovery > input { margin: 0; }

.group-results {
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.group-result-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.group-result-row:last-child { border-bottom: none; }
.group-result-info p { margin: 2px 0 0; }
.group-result-name { color: var(--pill-text); font-weight: 700; text-decoration: none; }
.group-result-name:hover { color: var(--accent); }

.person-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    font-size: .88rem;
}
.person-row > a, .person-row > span:first-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.person-actions { display: flex; gap: 6px; flex-shrink: 0; }

.btn.tiny {
    padding: 4px 10px;
    font-size: .72rem;
    border-width: 1px;
}
.btn.tiny.is-following { background: transparent; color: var(--muted); border-color: var(--border); }

/* ---- feed tabs + search ---- */
.feed-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--border);
}
.feed-tab {
    background: none;
    border: none;
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    padding: 8px 6px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.feed-tab:hover { color: var(--text); }
.feed-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- admin ---- */
.admin-main { max-width: 1000px; margin: 0 auto; padding: 20px 16px; }
.admin-main h1 { font-size: 1.1rem; margin: 0 0 12px; }
.admin-main h2 { font-size: .85rem; color: var(--muted); margin: 0 0 6px; }

.admin-totals { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.admin-stat {
    flex: 1 1 90px;
    background: var(--field);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}
.admin-stat-value { font-size: 1.3rem; font-weight: 900; color: var(--accent); }
.admin-stat-label { font-size: .75rem; color: var(--muted); }

.admin-chart { margin-bottom: 16px; }
.admin-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 60px;
    background: var(--field);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
}
.admin-bar { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; }

.admin-users { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 10px; }
.admin-users th, .admin-users td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.admin-users th { color: var(--muted); font-weight: 600; font-size: .75rem; }

.admin-pager { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

.admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.admin-tab {
    background: var(--field); color: var(--muted); border: 1px solid var(--border);
    border-radius: 999px; padding: 8px 18px; font: inherit; font-weight: 600; cursor: pointer;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent-text); background: var(--accent-dark); border-color: var(--accent); }
.admin-tab.small { padding: 5px 14px; font-size: .85rem; }
.admin-range { display: flex; gap: 8px; margin-bottom: 12px; }

.admin-delta { font-size: .72rem; margin-top: 4px; color: var(--muted); }
.admin-delta.up { color: #6fcf8a; }
.admin-delta.down { color: #e0a060; }
.admin-delta.bad { color: var(--error); }
.accent-text { color: var(--accent); }
.danger-text { color: var(--error); }

.admin-charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.admin-charts-grid .admin-chart { margin: 0; }
.admin-bars { height: 72px; }
.admin-axis { display: flex; justify-content: space-between; font-size: .68rem; color: var(--muted); margin-top: 3px; }

.admin-two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.admin-two .card { margin-bottom: 0; }

.admin-hbar { margin: 8px 0; }
.admin-hbar-label { font-size: .82rem; margin-bottom: 3px; }
.admin-hbar-track { height: 10px; background: var(--field); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.admin-hbar-fill { height: 100%; background: var(--accent); }

.admin-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.admin-toolbar input[type=text] { flex: 1 1 200px; min-width: 0; }
.admin-toolbar select {
    background: var(--field); color: var(--text); border: 1px solid var(--border);
    border-radius: 6px; padding: 7px 8px; font: inherit;
}
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-users td { white-space: nowrap; }
.admin-users a { color: var(--text); }
.admin-users a:hover { color: var(--accent); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; color: var(--muted); }
tr.ev-bad td { color: var(--error); }

@media (max-width: 600px) {
    .admin-main { padding: 12px 10px; }
    .admin-stat { flex-basis: 42%; }
}

/* ---- group invites ---- */
.desc-row { display: flex; align-items: baseline; gap: 8px; }
.desc-row p { margin: 0; }

.invite-manager { display: flex; flex-direction: column; gap: 4px; }
.invite-manager h2 { margin: 0; font-size: 1.1rem; }
.invite-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.invite-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--field);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    flex-wrap: wrap;
}
.invite-url { flex: 1 1 auto; min-width: 0; color: var(--pill-text); font-size: .8rem; overflow-wrap: anywhere; }

/* ---- phone ---- */
html { -webkit-text-size-adjust: 100%; }
body { touch-action: manipulation; }   /* no double-tap-zoom delay on taps */
a, button { -webkit-tap-highlight-color: rgba(255, 0, 0, .15); }
.install-box .btn { margin-bottom: 6px; }
.install-box { display: none; }   /* home-screen install only makes sense on phones/tablets — see the ≤900px rule below */

@media (max-width: 600px) {
    .topbar { padding: 0 10px; gap: 8px; }
    .brand { font-size: 1.05rem; }
    .authbox { gap: 6px; flex-wrap: nowrap; }
    .authbox .link-btn, .authbox .btn.small { padding: 6px 10px; font-size: .82rem; white-space: nowrap; }
    .who { max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }

    .wrap { padding: 14px 12px calc(80px + env(safe-area-inset-bottom)); }
    .card { padding: 14px; }
    .profile-head { flex-wrap: wrap; }
    .new-post-foot { flex-wrap: wrap; }
    .feed-tab { flex: 1; text-align: center; padding: 12px 4px; }
    .post-image { max-height: 420px; }

    /* dialogs use nearly the full screen width and scroll if the content is tall */
    #auth-modal, #util-modal {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 24px);
        overflow-y: auto;
        padding: 18px;
    }
}

/* Very narrow phones: drop the name link (the Profile tab covers it) so the bar never overflows. */
@media (max-width: 480px) {
    .who { display: none; }
    .authbox .link-btn, .authbox .btn.small { padding: 6px 9px; font-size: .78rem; }
}

/* Touch screens: fingertip-sized targets. */
@media (pointer: coarse) {
    .link-btn { min-height: 36px; }
    .vote-btn { padding: 10px 12px; font-size: .95rem; }
    .btn.small { padding: 8px 14px; }
    .btn.tiny { padding: 8px 14px; font-size: .78rem; }
    .add-btn { width: 36px; height: 36px; }
    .follow-row { padding: 11px 10px; }
    .feed-tab { padding: 12px 8px; }
    .post-actions { gap: 10px; }
    .comment-actions { gap: 8px; }
    .owner-menu { gap: 4px; }
    .modal-x { top: 8px; right: 8px; }
    .modal-x button { min-width: 44px; min-height: 44px; }
}

/* ---- landing, footer, policy pages, ads ---- */
.landing h1 { margin-top: 0; }
.landing h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.landing-points, .landing-groups { padding-left: 20px; margin: 8px 0; }
.landing-points li, .landing-groups li { margin: 6px 0; }
.landing a, .doc a { color: var(--accent); }

.site-footer { text-align: center; padding: 22px 0 12px; font-size: .85rem; color: var(--muted); }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

.doc { max-width: 760px; margin: 0 auto; }
.doc h1 { margin-top: 0; }
.doc h2 { font-size: 1.1rem; margin: 22px 0 6px; }
.doc ul { padding-left: 22px; }
.doc li { margin: 6px 0; }
.doc p, .doc li { line-height: 1.55; }

.ad-card { padding: 10px 14px 12px; overflow: hidden; }
.ad-label { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.ad-card ins.adsbygoogle { min-height: 0; }
.ad-card:has(ins.adsbygoogle[data-ad-status="unfilled"]) { display: none; }

/* ---- messaging ---- */
.msg-badge {
    background: var(--accent); color: var(--accent-text);
    font-size: .7rem; font-weight: 700; line-height: 1;
    min-width: 1.5em; height: 1.5em; padding: 0 .4em; border-radius: 1em;
    display: inline-grid; place-items: center;
}
.msg-badge[hidden] { display: none; }
.msg-link { display: inline-flex; align-items: center; gap: 6px; }

/* Keep the feed column a steady width beside the sidebar and dock, whatever it currently contains. */
.layout > .wrap { flex: 1 1 0; min-width: 260px; max-width: none; order: 3; }   /* takes all the space between the side panes */

/* Messages dock: a panel to the right of the feed, toggled by the ✉ icon. The conversation is on the
   left and the "Messages" chat list on its right (DOM order = visual order). */
.chat-dock {
    /* The conversation pane's width is user-resizable (--w-chat); the "Messages" list pane beside it is a fixed
       250px against the right edge, so the dock is always at least list + gap + the minimum conversation width. */
    box-sizing: border-box;
    width: calc(var(--w-chat, 340px) + 12px + 250px);
    max-width: 75vw;
    flex-shrink: 0; align-self: flex-start; order: 5;
    position: sticky; top: 76px; margin: 0;
    height: calc(100vh - 92px); height: calc(100dvh - 92px); min-height: 380px;
    container-type: inline-size; container-name: dock;
}

.chat-dock[hidden] { display: none; }
.msg-app { display: grid; grid-template-columns: minmax(0, 1fr) 250px; gap: 12px; height: 100%; }
.msg-toggle.active { background: var(--accent-dark); color: #fff; }
.msg-toggle.pulse { animation: msg-pulse 1.2s ease-out 2; }
@keyframes msg-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(255, 0, 0, .85); }
    100% { box-shadow: 0 0 0 14px rgba(255, 0, 0, 0); }
}
.msg-head-btns { display: flex; align-items: center; gap: 6px; }
.msg-close { background: none; border: none; color: var(--muted); font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0 6px; }
.msg-close:hover { color: var(--accent); }
.msg-head .msg-close { display: none; }      /* the list pane's own × is enough while both panes are visible */
.msg-side, .msg-main { margin: 0; padding: 0; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.msg-side-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.msg-side-head h2 { margin: 0; font-size: 1.05rem; }
.msg-list { flex: 1; min-height: 0; overflow-y: auto; }
.msg-item {
    display: flex; gap: 10px; align-items: center; padding: 10px 14px;
    color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border);
}
.msg-item:hover { background: var(--field); }
.msg-item.active { background: var(--field); box-shadow: inset 3px 0 0 var(--accent); }
.msg-item .avatar { flex-shrink: 0; }
.msg-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-item-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-item-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item-time { color: var(--muted); font-size: .72rem; flex-shrink: 0; }
.msg-item-preview { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item-preview.unread { color: var(--text); font-weight: 600; }
.msg-section { padding: 8px 14px; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--field); }
.msg-side-foot { padding: 8px 14px; border-top: 1px solid var(--border); }
.msg-empty { padding: 16px; }

.msg-thread { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.msg-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.msg-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.msg-title strong, .msg-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-back { display: none; font-size: 1.9rem; line-height: 1; color: var(--accent); text-decoration: none; padding: 0 8px 4px; }
.msg-head-actions { display: flex; gap: 6px; }
.msg-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; overscroll-behavior: contain; }
.msg-day { text-align: center; color: var(--muted); font-size: .72rem; margin: 10px 0; }
.msg-system { text-align: center; color: var(--muted); font-size: .8rem; margin: 8px 0; }
.msg-row { display: flex; margin: 3px 0; }
.msg-row.mine { justify-content: flex-end; }
.msg-bubble {
    max-width: 78%; padding: 8px 12px; border-radius: 16px;
    background: var(--field); border: 1px solid var(--border);
    overflow-wrap: anywhere;
}
.msg-row.mine .msg-bubble { background: var(--accent-dark); border-color: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.theirs .msg-bubble { border-bottom-left-radius: 4px; }
.msg-bubble.deleted { background: transparent; border-style: dashed; }
.msg-text { white-space: pre-wrap; }
.msg-sender { font-size: .72rem; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.msg-imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.msg-img { display: block; max-width: 220px; max-height: 220px; border-radius: 10px; object-fit: cover; }
.msg-meta { display: flex; gap: 10px; align-items: center; justify-content: flex-end; font-size: .68rem; color: var(--muted); margin-top: 2px; }
.msg-row.mine .msg-meta { color: #ffd0d0; }
.msg-act { background: none; border: none; padding: 0; font: inherit; font-size: .68rem; color: inherit; text-decoration: underline; cursor: pointer; opacity: .85; }

.msg-chrome { border-top: 1px solid var(--border); padding: 10px 12px; }
.msg-note { margin: 0; text-align: center; }
.msg-request { background: var(--field); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.msg-request p { margin: 0 0 8px; }
.msg-request-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg-compose-row { display: flex; gap: 8px; align-items: flex-end; }
.msg-compose-row textarea { margin: 0; flex: 1; min-height: 40px; max-height: 140px; resize: none; border-radius: 20px; padding: 9px 14px; }
.msg-attach { cursor: pointer; font-size: 1.3rem; padding: 6px; user-select: none; }
.msg-error { margin: 6px 0 0; }
.msg-previews { margin: 0 0 8px; }
.msg-placeholder { flex: 1; display: grid; place-items: center; text-align: center; padding: 20px; }
.msg-loading { padding: 16px; }

.btn.ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn.ghost:hover:not(:disabled) { background: var(--field); color: var(--text); box-shadow: none; transform: none; }
.btn.danger-btn { border-color: var(--error); color: var(--error); }
.btn.danger-btn:hover:not(:disabled) { background: var(--error); color: #000; box-shadow: none; }

.dialog-body h2 { margin-top: 0; }
.dialog-sub { font-size: .9rem; color: var(--muted); margin: 16px 0 6px; }
.dialog-sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.dialog-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.pick-list { max-height: 200px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; margin: 8px 0; }
.pick-row { padding: 5px 0; }
.add-row { display: flex; gap: 8px; align-items: center; }
.dialog-body select {
    background: var(--field); color: var(--text); border: 1px solid var(--border);
    border-radius: 8px; padding: 8px; font: inherit; flex: 1; min-width: 0;
}

/* Desktop: sidebar, feed and dock all begin at y=76 and stick at y=76 (same offset both ways), with identical
   heights — so they never nudge when the feed scrolls. Splitters sit between them. */
@media (min-width: 901px) {
    .layout { gap: 0; padding: 24px 8px 0; justify-content: flex-start; }   /* side panes hug the window edges */
    .layout > .wrap { padding-top: 0; margin: 0; }   /* no auto margins: they would swallow the free space and detach the columns */
    .splitter {
        display: block; flex: 0 0 14px; order: 2; align-self: flex-start; position: sticky; top: 76px;
        height: calc(100vh - 92px); height: calc(100dvh - 92px);
        cursor: col-resize; touch-action: none; outline: none;
    }
    #split-right { order: 4; }
    .splitter::before {
        content: ''; position: absolute; left: 6px; top: 10%; bottom: 10%; width: 2px; border-radius: 2px;
        background: var(--border); transition: background .15s;
    }
    .splitter:hover::before, .splitter:focus-visible::before, .splitter.dragging::before { background: var(--accent); }
    .splitter[hidden] { display: none; }
    body.resizing { cursor: col-resize; user-select: none; }
}
@media (max-width: 900px) { .splitter { display: none; } }

/* One pane at a time (the list, or the open conversation with a back button) only when the dock is too narrow for
   both — the floating overlay on small screens. The in-flow dock is never narrower than ~522px, so on desktop the
   "Messages" list can't disappear. */
@container dock (max-width: 499px) {
    .msg-app { grid-template-columns: 1fr; }
    .msg-app .msg-main { display: none; }
    .msg-app.thread-open .msg-side { display: none; }
    .msg-app.thread-open .msg-main { display: flex; }
    .msg-back { display: block; }
    .msg-head .msg-close { display: inline-block; }
}
/* Small screens: the dock floats over the page instead of sitting beside the feed. */
@media (max-width: 1279px) {
    .chat-dock {
        /* explicit height: with align-self:flex-start, top+bottom alone would shrink it to its content */
        position: fixed; top: 60px; right: 8px; align-self: auto; margin: 0; min-height: 0; max-width: none;
        height: calc(100vh - 68px); height: calc(100dvh - 68px);
        width: min(420px, calc(100vw - 16px)); z-index: 900; box-shadow: 0 10px 40px rgba(0, 0, 0, .7);
    }
}
@media (max-width: 700px) {
    .chat-dock { top: 52px; left: 0; right: 0; width: auto; height: calc(100vh - 52px); height: calc(100dvh - 52px); box-shadow: none; }
    .chat-dock .msg-side, .chat-dock .msg-main { border-radius: 0; border-left: 0; border-right: 0; }
    .msg-bubble { max-width: 88%; }
}
@media (max-width: 480px) {
    .authbox { gap: 6px; }
    .authbox .link-btn { padding: 6px 10px; }
}

/* ---- admin: reports ---- */
.rep-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 12px 0; background: var(--field); }
.rep-head { margin-bottom: 6px; }
.rep-context { border-left: 2px solid var(--border); padding-left: 10px; margin: 6px 0; font-size: .85rem; }
.rep-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.rep-message { margin: 8px 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--card); white-space: pre-wrap; overflow-wrap: anywhere; }
.rep-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.admin-tab .msg-badge { margin-left: 4px; }

/* `hidden` must win over the display set on these (used when Messages replaces the feed view) */
.feed-tabs[hidden] { display: none; }

/* ---- scrollbars: dark track, dark-red thumb (brightens on hover where the browser lets us) ---- */
:root { scrollbar-color: var(--accent-dark) var(--bg); }
.sidebar, .msg-scroll, .msg-list, .pick-list, .msg-compose-row textarea, .dialog-body {
    scrollbar-width: thin;
    scrollbar-color: var(--accent-dark) var(--card);
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--accent-dark); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
::-webkit-scrollbar-corner { background: var(--bg); }

/* ---- desktop: the "Messages" list is always there; the conversation pane beside it can be hidden with » ---- */
.msg-hide { display: none; background: none; border: none; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 0 6px; }
.msg-hide:hover { color: var(--accent); }
.msg-empty-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.msg-head-empty .msg-title { flex: 1; }
.msg-side-head h2 .msg-badge { margin-left: 8px; vertical-align: middle; }
.msg-badge.pulse { animation: msg-pulse 1.2s ease-out 2; }
@media (min-width: 1280px) {
    .authbox .msg-toggle { display: none !important; }       /* the list pane is always visible, so no envelope needed */
    .msg-hide { display: inline-block; }
    .msg-side-head .msg-close { display: none; }             /* the list pane can't be closed on desktop */
    .chat-dock.chat-off { width: 250px; }                    /* conversation hidden: the dock is just the list pane */
    .chat-dock.chat-off .msg-main { display: none; }
    .chat-dock.chat-off .msg-app { grid-template-columns: 250px; }
    .chat-dock.chat-off .msg-side { display: flex !important; }
}

/* ---- chat header: the "⋯" options menu (Block / Group settings) sits by the name, far from » and × ---- */
.msg-title-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; }
.msg-title-wrap .msg-title { flex: 0 1 auto; min-width: 0; }
.msg-menu-wrap { position: relative; flex-shrink: 0; }
.msg-menu-btn {
    background: none; border: none; color: var(--muted); font-size: 1.3rem; line-height: 1;
    padding: 2px 8px; border-radius: 6px; cursor: pointer;
}
.msg-menu-btn:hover, .msg-menu-btn[aria-expanded="true"] { color: var(--text); background: var(--field); }
.msg-menu {
    position: absolute; top: calc(100% + 12px); left: 0; z-index: 30; min-width: 190px; max-width: 260px;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .6);
}
.msg-menu[hidden] { display: none; }
.msg-menu-item {
    display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
    font: inherit; padding: 8px 10px; border-radius: 7px; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-menu-item:hover, .msg-menu-item:focus-visible { background: var(--field); outline: none; }
.msg-menu-item.danger { color: var(--error); }
/* however long the chat name is, keep a real gap between the ⋯ options button and the » / × on the right */
.msg-head .msg-head-actions { margin-left: 24px; flex-shrink: 0; }

/* new-post counters in the left panel: a badge beside each name, and a total beside each heading */
.follow-badge[hidden] { display: none; }
.sidebar-title .unseen-total { display: inline-grid; margin-left: 6px; vertical-align: middle; }
.sidebar-title .unseen-total[hidden] { display: none; }      /* must out-rank the rule above */

/* report category pill in the admin queue */
.rep-cat { display: inline-block; padding: 1px 9px; border: 1px solid var(--accent); border-radius: 999px; color: var(--pill-text); font-size: .75rem; font-weight: 700; margin-right: 4px; }
