:root {
    --bg: #000000;
    --bg-accent: #2f4550;
    --surface: rgba(47, 69, 80, 0.92);
    --surface-strong: #2f4550;
    --surface-soft: #586f7c;
    --border: rgba(184, 219, 217, 0.28);
    --text: #f4f4f9;
    --muted: #b8dbd9;
    --primary: #b8dbd9;
    --primary-strong: #586f7c;
    --success: #b8dbd9;
    --danger: #f4f4f9;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 0 16px 32px;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top, rgba(184, 219, 217, 0.18), transparent 32%),
        linear-gradient(180deg, #000000 0%, #2f4550 100%);
}

.app-layout {
    display: grid;
    grid-template-columns: 270px minmax(0, 960px);
    align-items: start;
    justify-content: center;
    gap: 28px;
    width: min(1280px, 100%);
    margin: 0 auto;
}

.container {
    width: 960px;
    max-width: 100%;
    margin: 32px 0 0;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: rgba(47, 69, 80, 0.82);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-header-copy {
    min-width: 0;
}

.page-header-logo {
    display: block;
    width: min(260px, 34%);
    max-height: 120px;
    object-fit: contain;
    object-position: center right;
    flex: 0 0 auto;
}

.eyebrow {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--primary);
}

h1,
h2,
h3,
h4,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 4vw, 40px);
}

.container > h1 {
    margin-bottom: 24px;
}

h2 {
    margin-bottom: 20px;
    font-size: 24px;
}

.posts-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.profile-link,
.nav a {
    display: inline-flex;
    align-items: center;
    gap: 18px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid transparent;
    background: transparent;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.profile-link {
    padding: 12px 14px;
    border-radius: 999px;
    white-space: nowrap;
    font-size: 20px;
    font-weight: 700;
}

.side-nav {
    position: sticky;
    top: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px 12px 28px 0;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.side-nav .profile-link {
    width: 100%;
    justify-content: flex-start;
}

.profile-link:hover,
.nav a:hover {
    transform: translateY(-1px);
    background: rgba(88, 111, 124, 0.55);
}

.profile-link.active,
.side-nav .nav a.active {
    color: var(--primary);
    background: rgba(184, 219, 217, 0.14);
    border-color: rgba(184, 219, 217, 0.36);
}

.profile-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(184, 219, 217, 0.18);
    overflow: hidden;
    flex: 0 0 auto;
}

.profile-link-icon img,
.post-avatar img,
.profile-photo-control img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.side-nav .nav {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    margin-bottom: 0;
}

.side-nav .nav a {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: 999px;
    font-size: 20px;
    font-weight: 600;
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    min-width: 28px;
    height: 28px;
    font-size: 20px;
    line-height: 1;
}

.side-nav .nav-primary {
    display: inline-flex;
    align-items: center;
    gap: 18px;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 999px;
    font-weight: 700;
}

.side-nav .side-post-button {
    justify-content: center;
    width: 100%;
    margin-top: auto;
    padding: 14px 18px;
    color: #000000;
    background: var(--text);
    font-size: 17px;
}

.side-nav .side-post-button:hover {
    transform: translateY(-1px);
    background: #b8dbd9;
}

.side-nav .side-post-button.active {
    box-shadow: 0 0 0 3px rgba(184, 219, 217, 0.24);
}

label {
    font-weight: 600;
    color: var(--muted);
}

input,
textarea,
select,
button {
    width: 100%;
    margin-bottom: 12px;
    padding: 11px 13px;
    font-size: 14px;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-strong);
}

input:focus,
textarea:focus,
select:focus,
button:focus {
    outline: 2px solid rgba(184, 219, 217, 0.42);
    outline-offset: 2px;
}

button {
    cursor: pointer;
    width: auto;
    color: #000000;
    background: linear-gradient(180deg, var(--primary), var(--primary-strong));
    border: none;
    font-weight: 600;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

button:hover {
    transform: translateY(-1px);
    opacity: 0.96;
}

.sort-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(47, 69, 80, 0.66);
}

.sort-form label,
.sort-form select,
.sort-form button {
    margin-bottom: 0;
}

.sort-form select {
    width: 220px;
}

.compact-sort {
    display: grid;
    grid-template-columns: auto minmax(150px, 1fr) auto minmax(150px, 1fr);
    margin-bottom: 0;
    margin-left: auto;
    padding: 8px 10px;
    gap: 8px;
    align-items: center;
    border-radius: 14px;
}

.compact-sort label {
    margin: 0;
    font-size: 13px;
    white-space: nowrap;
}

.compact-sort select {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    font-size: 13px;
}

.post-card,
.profile-card {
    margin-bottom: 20px;
    padding: 22px;
    scroll-margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(47, 69, 80, 0.96), rgba(47, 69, 80, 0.82));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.post-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.post-author {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.post-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: rgba(184, 219, 217, 0.18);
    overflow: hidden;
    flex: 0 0 auto;
}

.post-card h3 {
    margin-bottom: 8px;
}

.author-link {
    color: var(--text);
    text-decoration: none;
}

.author-link:hover {
    color: var(--primary);
    text-decoration: underline;
}

.post-meta,
.post-date,
.current-reaction,
.comment small {
    color: var(--muted);
}

.post-date {
    margin-bottom: 0;
    white-space: nowrap;
}

.post-content {
    margin: 18px 0;
    line-height: 1.6;
}

.post-media {
    margin: 0 0 18px;
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.74);
}

.post-media img,
.post-media video {
    display: block;
    background: #000000;
}

.post-media img {
    width: 100%;
    height: auto;
}

.post-media video {
    width: 100%;
    max-height: 480px;
    object-fit: contain;
}

.post-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.post-stats form {
    margin: 0;
}

.post-stats > .stat-pill {
    width: auto;
    margin-bottom: 0;
}

.stat-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    margin-bottom: 0;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(88, 111, 124, 0.58);
    color: var(--text);
    line-height: 1;
}

.stat-action {
    width: auto;
    margin-bottom: 0;
    cursor: pointer;
    color: var(--text);
    font: inherit;
}

.stat-action:hover,
.comment-toggle:hover {
    transform: translateY(-1px);
    border-color: rgba(184, 219, 217, 0.48);
    opacity: 1;
}

.reaction-buttons {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.reaction-buttons form,
.post-card form {
    margin: 0;
}

.icon-button,
.saved-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border-radius: 50%;
    font-size: 18px;
}

.icon-button {
    color: var(--text);
    background: linear-gradient(180deg, rgba(88, 111, 124, 0.96), rgba(47, 69, 80, 0.96));
    border: 1px solid var(--border);
}

.active-like {
    color: #000000;
    background: linear-gradient(180deg, #b8dbd9, #586f7c);
}

.active-dislike {
    color: #000000;
    background: linear-gradient(180deg, #f4f4f9, #b8dbd9);
}

.saved-indicator {
    color: var(--success);
    border: 1px solid rgba(184, 219, 217, 0.32);
    background: rgba(184, 219, 217, 0.12);
}

.post-stats .icon-button,
.post-stats .saved-indicator {
    width: auto;
    min-width: 46px;
    height: 38px;
    min-height: 38px;
    margin-bottom: 0;
    padding: 0 14px;
    border-radius: 999px;
    line-height: 1;
}

.comments-section {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.comment-form-toggle {
    position: relative;
}

.comment-form-toggle summary {
    width: fit-content;
    cursor: pointer;
    list-style: none;
}

.comment-form-toggle summary::-webkit-details-marker {
    display: none;
}

.comment-popover {
    position: absolute;
    z-index: 5;
    top: calc(100% + 10px);
    left: 0;
    width: min(360px, 82vw);
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface-strong);
    box-shadow: var(--shadow);
}

.comment-popover textarea {
    min-height: 92px;
}

.comment {
    margin-bottom: 10px;
    padding: 12px 14px;
    border: 1px solid rgba(184, 219, 217, 0.18);
    border-radius: 14px;
    background: rgba(88, 111, 124, 0.34);
}

.comment p {
    margin-bottom: 6px;
}

.comment-form textarea {
    min-height: 96px;
    resize: vertical;
}

.field-hint {
    margin-top: -2px;
    margin-bottom: 16px;
    font-size: 13px;
    color: var(--muted);
}

.form-message {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid rgba(184, 219, 217, 0.36);
    border-radius: 14px;
    background: rgba(88, 111, 124, 0.32);
    color: #f4f4f9;
}

.profile-card-header {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 18px;
}

.profile-card-header h2 {
    margin-bottom: 0;
}

.profile-photo-form {
    margin: 0;
}

.profile-photo-form input[type="file"] {
    display: none;
}

.profile-photo-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 88px;
    height: 88px;
    margin: 0;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 50%;
    background: rgba(184, 219, 217, 0.18);
    cursor: pointer;
    overflow: hidden;
    font-size: 34px;
    transition: transform 0.18s ease, border-color 0.18s ease;
}

.profile-photo-control:hover {
    transform: translateY(-1px);
    border-color: rgba(184, 219, 217, 0.48);
}

.profile-photo-control.static {
    cursor: default;
}

.profile-photo-control.static:hover {
    transform: none;
    border-color: var(--border);
}

.profile-actions {
    margin: -4px 0 18px;
}

.follow-button {
    min-width: 150px;
}

.follow-button.secondary {
    color: var(--text);
    border: 1px solid var(--border);
    background: var(--surface-soft);
}

.search-form {
    margin-bottom: 22px;
}

.search-form label {
    display: block;
    margin-bottom: 8px;
}

.search-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.search-row input {
    min-height: 44px;
    margin-bottom: 0;
}

.search-row button {
    flex: 0 0 auto;
    min-height: 44px;
    margin-bottom: 0;
}

.search-row input:focus {
    outline: none;
    border-color: rgba(184, 219, 217, 0.72);
    box-shadow: 0 0 0 3px rgba(184, 219, 217, 0.18);
}

.user-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-result-card {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 16px;
    color: var(--text);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(47, 69, 80, 0.96), rgba(47, 69, 80, 0.82));
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.user-result-card:hover {
    transform: translateY(-1px);
    border-color: rgba(184, 219, 217, 0.48);
    background: rgba(88, 111, 124, 0.55);
}

.user-result-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.user-result-body span,
.user-result-body small,
.empty-state {
    color: var(--muted);
}

@media (max-width: 1080px) {
    body {
        padding: 18px 10px 92px;
        overflow-x: hidden;
    }

    .app-layout {
        display: block;
        width: 100%;
        margin: 0;
    }

    .side-nav {
        position: fixed;
        z-index: 20;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 72px;
        min-height: 0;
        max-height: 72px;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        align-items: center;
        justify-items: center;
        gap: 0;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
        border-right: 0;
        border-top: 1px solid var(--border);
        border-bottom: 0;
        background: rgba(0, 0, 0, 0.94);
        backdrop-filter: blur(14px);
        overflow: visible;
    }

    .side-nav .nav {
        display: contents;
    }

    .side-nav .nav a,
    .side-nav .profile-link,
    .side-nav .side-post-button {
        display: flex;
        align-items: center;
        width: 48px;
        min-width: 48px;
        height: 48px;
        min-height: 48px;
        margin: 0;
        padding: 0;
        justify-content: center;
        gap: 0;
        border-radius: 50%;
        font-size: 0;
        line-height: 1;
    }

    .side-nav .nav a[href="logout.php"] {
        display: none;
    }

    .side-nav .nav a[href="index.php"] {
        grid-column: 1;
        order: 1;
    }

    .side-nav .nav a[href="search.php"] {
        grid-column: 2;
        order: 2;
    }

    .side-nav .side-post-button {
        grid-column: 3;
        order: 3;
        flex: 0 0 54px;
        width: 54px;
        height: 54px;
        color: #000000;
        background: var(--primary);
    }

    .side-nav .nav a[href="saved_posts.php"] {
        grid-column: 4;
        order: 4;
    }

    .side-nav .profile-link {
        grid-column: 5;
        order: 5;
        align-self: center;
    }

    .side-nav .nav a::before,
    .side-nav .side-post-button .nav-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        min-width: 28px;
        height: 28px;
        margin: 0;
        font-size: 23px;
        line-height: 1;
    }

    .side-nav .side-post-button .nav-icon {
        transform: none;
    }

    .side-nav .nav a[href="index.php"]::before {
        content: "\2302";
    }

    .side-nav .nav a[href="search.php"]::before {
        content: "\1F50D";
    }

    .side-nav .nav a[href="saved_posts.php"]::before {
        content: "\1F516";
    }

    .side-nav .side-post-button span:not(.nav-icon),
    .side-nav .profile-link > span:not(.profile-link-icon) {
        display: none;
    }

    .side-nav .profile-link-icon {
        width: 34px;
        height: 34px;
        font-size: 18px;
    }

    .container {
        margin: 0;
        padding: 18px;
        border-radius: 18px;
    }

    .page-header,
    .post-header,
    .posts-heading {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header-logo {
        width: min(180px, 58vw);
        max-height: 84px;
        object-position: left center;
    }

    .sort-form select,
    .sort-form button,
    .compact-sort select {
        width: 100%;
    }

    .search-row {
        flex-direction: column;
    }

    .search-row button {
        width: 100%;
    }

    .post-date {
        white-space: normal;
    }
}
