/* === APP LAYOUT === */
#app-layout {
    display: block;
    min-height: 100vh;
    position: relative;
}

/* === TOPBAR (Mobile) === */
.topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(10, 10, 12, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 16px;
    z-index: 1100;
    align-items: center;
    justify-content: space-between;
}

.topbar .logo,
.topbar a.logo,
.topbar a.logo:hover,
.topbar a.logo:visited {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 20px;
    background: linear-gradient(135deg, #06b6d4 0%, #4ade80 100%) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    color: transparent !important;
    text-decoration: none !important;
}

.topbar-nav-dropdown {
    position: relative;
}

.topbar-nav-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.topbar-nav-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
}

.dropdown-arrow {
    font-size: 10px;
    opacity: 0.7;
    transition: transform 0.2s;
}

.topbar-nav-dropdown.active .dropdown-arrow {
    transform: rotate(180deg);
}

.topbar-nav-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 12, 18, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    min-width: 140px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    z-index: 1200;
    overflow: hidden;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.topbar-nav-item {
    display: block;
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    text-decoration: none;
    transition: all 0.2s;
    border: none;
    background: none;
    width: 100%;
    text-align: center;
    cursor: pointer;
    border-radius: 8px;
}

.topbar-nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.topbar-nav-item.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Utility */
.hidden {
    display: none !important;
}

.pax-badge {
    font-size: 13px;
    color: var(--accent-cyan);
    font-weight: 600;
}

.cred-badge {
    font-size: 13px;
    color: var(--accent-green);
    font-weight: 600;
}

.user-menu-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-green);
    color: #fff;
    position: relative;
    font-weight: 700;
    font-size: 14px;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* User Menu Dropdown */
.user-menu {
    position: fixed;
    top: 60px;
    right: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    min-width: 200px;
    z-index: 200;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.user-menu.hidden {
    display: none;
}

.user-menu-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.user-menu-header strong {
    display: block;
    margin-bottom: 4px;
}

.menu-stats {
    font-size: 12px;
    color: var(--secondary);
    display: flex;
    gap: 12px;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 14px;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.menu-item-danger {
    color: #ef4444;
}

.menu-item-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

.menu-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: 8px 0;
}

/* === SIDEBAR (Desktop) === */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 260px;
    padding: 24px;
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    background: rgba(20, 20, 22, 0.8);
    backdrop-filter: blur(16px);
    z-index: 50;
}

.sidebar-header {
    margin-bottom: 32px;
    text-align: center;
}

.sidebar-header .logo {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 36px;
    background: linear-gradient(135deg, #06b6d4 0%, #4ade80 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    display: inline-block;
    letter-spacing: -1px;
    text-decoration: none;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    border: 1px solid var(--border-subtle);
}

.avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    flex-shrink: 0;
    background: var(--accent-green);
    border-radius: 50%;
    display: flex;
    position: relative;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    font-size: 16px;
}

.u-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats {
    display: flex;
    gap: 12px;
    font-size: 12px;
}

.stat.pax {
    color: var(--accent-cyan);
}

.stat.cred {
    color: var(--accent-green);
}

.app-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.app-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    color: var(--secondary);
    font-weight: 500;
    font-size: 15px;
    transition: all 0.2s;
}

.app-nav a:hover,
.app-nav a.active {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.nav-icon {
    font-size: 18px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
}

/* === MAIN CONTENT === */
#main-content {
    min-height: 100vh;
    width: 100%;
    padding: 48px 0 24px 0;
    box-sizing: border-box;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

#main-content.feed,
#main-content.activity,
#main-content.arcade-main,
#main-content.leaderboard-main,
#main-content.profile-main,
#main-content.stats-main,
#main-content.chat-main {
    max-width: 800px;
    width: 100%;
    padding-left: 16px;
    padding-right: 16px;
    box-sizing: border-box;
}

#main-content.arcade-main,
#main-content.stats-main,
#main-content.chat-main {
    max-width: 1100px;
}

#main-content.feed {
    gap: 20px;
}

#main-content.activity {
    gap: 16px;
}

#main-content.arcade-main {
    max-width: 1000px;
    gap: 16px;
}

@media (max-width: 820px) {
    #main-content.arcade-main {
        max-width: 100%;
        padding-left: 0;
        padding-right: 0;
    }
}

/* Jigsaw view - fullscreen, no padding */
#main-content.jigsaw-main {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    height: 100vh !important;
    min-height: 100vh !important;
    overflow: hidden;
}

.feed-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    color: var(--accent-cyan);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.back-link svg {
    transition: transform 0.2s ease;
}

.back-link:hover svg {
    transform: translateX(-3px);
}

.back-link:hover {
    background: rgba(6, 182, 212, 0.15);
    border-color: rgba(6, 182, 212, 0.3);
    text-decoration: none;
}

.activity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.activity-title-wrap h2 {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
}

.activity-subtitle {
    color: var(--secondary);
    font-size: 14px;
    margin-top: 4px;
}

.feed-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.custom-sort {
    position: relative;
    display: inline-block;
    z-index: 20;
}

.btn-sort {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 80px;
    text-align: center;
}

.btn-sort:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-highlight);
}

.sort-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 160px;
    background: #1a1b1f;
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 1100;
    overflow: hidden;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sort-menu.hidden {
    display: none;
}

.sort-option {
    padding: 10px 12px;
    color: var(--secondary);
    font-size: 13px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.15s;
}

.sort-option:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

/* Filter menu styles */
.filter-menu {
    min-width: 280px;
    max-width: 320px;
}

.filter-section {
    padding: 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.filter-section:last-child {
    border-bottom: none;
}

.filter-label-small {
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.popular-tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.filter-tag-chip {
    cursor: pointer;
    font-size: 12px;
}

.filter-tag-chip .tag-count {
    font-size: 10px;
    opacity: 0.7;
    margin-left: 2px;
}

.filter-tag-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    box-sizing: border-box;
}

.filter-tag-input:focus {
    outline: none;
    border-color: var(--accent-cyan);
}

.filter-empty {
    color: var(--secondary);
    font-size: 12px;
    text-align: center;
    padding: 8px;
}

.feed-header h2 {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 600;
}

.filter {
    font-size: 14px;
    color: var(--secondary);
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 20px;
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.activity-item {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    align-items: center;
}

.activity-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.activity-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.activity-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.activity-label {
    font-weight: 700;
    color: #fff;
}

.activity-ts {
    color: var(--secondary);
    font-size: 12px;
}

.activity-actor {
    color: var(--accent-cyan);
    font-weight: 600;
    font-size: 14px;
}

.activity-detail {
    color: var(--primary);
    font-size: 14px;
    line-height: 1.5;
}

.activity-link-row {
    margin-top: 4px;
}

.activity-link {
    color: var(--accent-cyan);
    font-weight: 600;
    text-decoration: none;
}

.activity-link:hover {
    text-decoration: underline;
}

/* === RESPONSIVE === */
/* Hide sidebar and show topbar on mobile/tablet devices */
@media (max-width: 1199px) {
    .sidebar {
        display: none !important;
    }

    .topbar {
        display: flex;
    }

    #main-content {
        padding-top: 72px !important;
    }
}

@media (max-width: 768px) {
    #main-content {
        padding-left: 0;
        padding-right: 0;
    }

    /* Ensure view-specific padding doesn't override top padding */
    #main-content.feed,
    #main-content.activity,
    #main-content.arcade-main,
    #main-content.leaderboard-main,
    #main-content.profile-main,
    #main-content.chat-main {
        padding-top: 72px !important;
    }


    /* Add extra top margin to headers to prevent top bar blocking */
    .feed-header,
    .arcade-header,
    .activity-header,
    .leaderboard-header,
    .profile-header {
        margin-top: 0;
        padding-top: 0;
    }

    .arcade-header {
        margin-top: 24px;
    }

    .arcade-header h2 {
        margin-top: 0;
    }

    .feed-header h2 {
        margin-top: 0;
    }

    .activity-title-wrap h2 {
        margin-top: 0;
    }

    .leaderboard-title-wrap h2 {
        margin-top: 0;
    }

    /* Profile page mobile fixes */
    .profile-container {
        padding: 0;
        gap: 16px;
    }

    .profile-header {
        padding: 20px 16px 16px 16px;
        flex-direction: row;
        gap: 16px;
        margin-top: 0;
    }

    .profile-info {
        min-width: 0;
        flex: 1;
        overflow: hidden;
    }

    .profile-username-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        width: 100%;
    }

    .profile-username {
        font-size: 24px;
        width: 100%;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .profile-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-start;
    }

    .profile-actions .btn {
        flex: 0 1 auto;
        min-width: 100px;
    }

    .avatar-large {
        width: 64px;
        height: 64px;
        font-size: 24px;
        flex-shrink: 0;
    }

    .profile-stats {
        gap: 16px;
    }

    .profile-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .profile-tabs::-webkit-scrollbar {
        display: none;
    }

    .profile-tab {
        padding: 10px 16px;
        font-size: 14px;
        white-space: nowrap;
    }

    .feed {
        width: 100%;
        max-width: none;
        padding: 20px 16px;
    }

    .arcade-main {
        width: 100%;
        max-width: none;
        padding: 20px 16px;
    }

    #main-content.leaderboard-main {
        width: 100%;
        max-width: none;
        padding: 0 12px;
    }

    .feed-header h2 {
        font-size: 22px;
    }

    .create-post-card {
        padding: 16px;
    }

    .post-item {
        padding: 16px;
    }

    /* Post header mobile fixes */
    .post-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        position: relative;
    }

    .post-title-wrap {
        width: 100%;
    }

    .post-title-row {
        flex-wrap: nowrap;
        gap: 8px;
        width: 100%;
        align-items: center;
    }

    /* Keep title inline with button and image */
    .post-title {
        font-size: 16px;
        flex: 1;
        min-width: 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
    }

    /* Keep Open button, like count, and thumbnail on first line */
    .post-title-row .inline-toggle,
    .post-title-row .post-like-count-display,
    .post-title-row .btn-react,
    .post-title-row .post-thumb {
        flex-shrink: 0;
    }

    /* Position link button to align with author/time line */
    .post-title-row .btn-icon {
        /* Remove from title row flow but keep it visible */
        order: 0;
        width: auto;
        margin: 0;
        padding: 4px 8px;
        flex-shrink: 0;
        /* Position it to appear with author section */
        position: absolute;
        right: 0;
        /* Calculate position to align with author: height of title-wrap + gap */
        top: 100%;
        margin-top: 8px;
    }

    /* Make title-wrap position relative for absolute positioning */
    .post-title-wrap {
        position: relative;
    }

    /* Author and time on new line below title, with space for link button */
    .post-author {
        width: 100%;
        margin-top: 0;
        padding-right: 40px;
    }

    .auth-container {
        padding: 28px 24px;
    }

    .auth-logo {
        font-size: 26px;
        margin-bottom: 32px;
    }

    .auth-container h1 {
        font-size: 24px;
    }

    /* Comment form row mobile fixes */
    .comment-form-row {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .comment-form {
        flex: 1 1 0;
        min-width: 0;
        max-width: calc(100% - 80px);
    }

    .comment-form textarea {
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .custom-sort {
        flex-shrink: 0;
        width: auto;
        min-width: 70px;
    }

    .btn-sort {
        min-width: 70px;
        padding: 8px 12px;
        font-size: 12px;
        box-sizing: border-box;
    }

    /* Center sort/filter menus on mobile */
    .sort-menu {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    .sort-option {
        text-align: center;
    }
}

/* Larger screens - show sidebar, hide topbar */
@media (min-width: 1200px) {
    .sidebar {
        display: flex;
    }

    .topbar {
        display: none;
    }

    #main-content {
        padding-left: 260px;
    }
}

@media (min-width: 1400px) {
    .sidebar {
        width: 280px;
    }

    #main-content {
        padding-left: 280px;
    }

    #main-content.feed,
    #main-content.activity {
        max-width: 900px;
        padding: 0 40px;
    }

    #main-content.arcade-main {
        max-width: 1100px;
        padding: 0 40px;
    }

    #main-content.leaderboard-main {
        max-width: 900px;
        padding: 0 40px;
    }

    #main-content.profile-main {
        max-width: 900px;
        padding: 0 40px;
    }
}

/* Extra large screens */
@media (min-width: 1600px) {

    #main-content.feed,
    #main-content.activity,
    #main-content.leaderboard-main,
    #main-content.profile-main {
        max-width: 1000px;
    }

    #main-content #main-content.arcade-main {
        max-width: 1200px;
    }
}