:root {
    --bg: #141416;
    --bg-card: #1c1c1f;
    --bg-card-hover: #212125;
    --bg-surface: #1e1e22;
    --bg-elevated: #25252a;
    --bg-input: #1a1a1d;
    --accent: #4caf50;
    --accent-hover: #66bb6a;
    --accent-soft: rgba(76, 175, 80, 0.12);
    --green: #4caf50;
    --green-soft: rgba(76, 175, 80, 0.12);
    --red: #ef5350;
    --red-soft: rgba(239, 83, 80, 0.1);
    --blue: #5b9bd5;
    --text: #e0e0e0;
    --text-secondary: #9a9a9e;
    --text-muted: #6b6b70;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.1);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.55);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --sidebar-w: 320px;
    --header-h: 56px;
    --bottom-nav-h: 60px;
    --max-w: 1320px;
    --transition: 0.2s ease;
    --admin-bg: #0f1217;
    --admin-card: #1a1d23;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-tap-highlight-color: transparent; }
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
body.menu-open, body.sidebar-open, body.modal-open { overflow: hidden; touch-action: none; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

.container { max-width: var(--max-w); margin: 0 auto; padding: 0 16px; }

/* Header */
.header {
    position: sticky; top: 0; z-index: 200;
    background: rgba(20,20,22,0.85); backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border); height: var(--header-h);
    display: flex; align-items: center;
}
.header-inner {
    display: flex; align-items: center; gap: 12px;
    width: 100%; max-width: var(--max-w); margin: 0 auto; padding: 0 16px; height: 100%;
}
.header-logo {
    display: flex; align-items: center; gap: 6px; text-decoration: none; flex-shrink: 0;
    font-weight: 700; font-size: 1.35rem; color: #fff; letter-spacing: -0.03em;
}
.header-logo .logo-icon {
    width: 34px; height: 34px; border-radius: 10px; background: var(--accent);
    display: flex; align-items: center; justify-content: center; font-size: 1rem; color: #fff; font-weight: 700;
}
.header-back {
    color: var(--text); text-decoration: none; font-size: 0.9rem; font-weight: 500;
    display: flex; align-items: center; gap: 6px; transition: var(--transition); flex-shrink: 0;
}
.header-back:hover { color: #fff; }
.header-search { flex: 1 1 280px; max-width: 420px; position: relative; min-width: 0; }
.header-search input {
    width: 100%; background: var(--bg-input); border: 1px solid var(--border-strong);
    border-radius: 24px; padding: 9px 16px 9px 38px; color: var(--text); font-size: 0.88rem;
    outline: none; transition: var(--transition); font-family: inherit;
}
.header-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.header-search .search-icon {
    position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); font-size: 0.85rem; pointer-events: none;
}
.search-suggestions {
    position: absolute; top: calc(100% + 8px); left: 0; right: 0;
    background: var(--bg-elevated); border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); padding: 8px; display: none; z-index: 250;
    box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto;
}
.search-suggestions.active { display: block; }
.suggestion-item {
    padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer;
    display: flex; align-items: center; gap: 10px; font-size: 0.85rem;
    transition: var(--transition); color: var(--text);
}
.suggestion-item:hover { background: var(--accent-soft); }
.suggestion-item i { color: var(--text-muted); font-size: 0.75rem; width: 16px; text-align: center; }
.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto; }
.header-btn {
    width: 38px; height: 38px; border-radius: 50%; border: none; background: transparent;
    color: var(--text); cursor: pointer; font-size: 1.15rem; transition: var(--transition);
    display: flex; align-items: center; justify-content: center; position: relative;
    text-decoration: none; flex-shrink: 0;
}
.header-btn:hover { background: rgba(255,255,255,0.06); }
.header-btn .badge {
    position: absolute; top: 4px; right: 4px; width: 18px; height: 18px; border-radius: 50%;
    background: var(--accent); color: #fff; font-size: 0.6rem; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
}
.header-btn-create {
    background: var(--accent); color: #fff; border-radius: 24px; padding: 0 16px;
    width: auto; height: 36px; font-size: 0.85rem; font-weight: 500; gap: 6px; white-space: nowrap;
}
.header-btn-create:hover { background: var(--accent-hover); }
.header-avatar {
    width: 34px; height: 34px; border-radius: 50%; background: var(--bg-elevated);
    border: 2px solid var(--border-strong); cursor: pointer; overflow: hidden; transition: var(--transition);
}
.header-avatar:hover { border-color: var(--accent); }
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-dropdown {
    position: absolute; top: calc(100% + 8px); right: 0; min-width: 240px;
    background: var(--bg-elevated); border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); padding: 8px; box-shadow: var(--shadow-lg);
    opacity: 0; visibility: hidden; transform: translateY(-8px); transition: var(--transition); z-index: 260;
}
.user-dropdown.active { opacity: 1; visibility: visible; transform: translateY(0); }
.user-dropdown a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px;
    border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: 0.85rem;
    transition: var(--transition);
}
.user-dropdown a:hover { background: rgba(255,255,255,0.04); }
.user-dropdown a i { width: 18px; text-align: center; color: var(--text-muted); }
.user-dropdown hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0; display: flex; flex-direction: column; gap: 16px;
    position: sticky; top: calc(var(--header-h) + 48px); align-self: flex-start;
    max-height: calc(100vh - var(--header-h) - 64px); overflow-y: auto;
}
.sidebar-card {
    background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); padding: 16px;
}
.sidebar-card h4 {
    font-size: 0.9rem; font-weight: 600; margin-bottom: 12px;
    display: flex; align-items: center; gap: 8px; color: #fff;
}
.sidebar-card h4 i { color: var(--accent); font-size: 0.8rem; }
.sidebar-tag {
    display: inline-block; padding: 6px 12px; border-radius: 16px; font-size: 0.75rem;
    background: var(--bg-surface); color: var(--text-secondary); margin: 0 6px 8px 0;
    cursor: pointer; transition: var(--transition); text-decoration: none; border: 1px solid transparent;
}
.sidebar-tag:hover { border-color: var(--accent); color: #fff; }
.sidebar-community {
    display: flex; align-items: center; gap: 10px; padding: 8px; cursor: pointer;
    text-decoration: none; color: var(--text); transition: var(--transition); border-radius: var(--radius-sm);
}
.sidebar-community:hover { background: rgba(255,255,255,0.03); }
.sidebar-community .comm-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--bg-elevated);
    flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 0.85rem; color: var(--accent);
}
.sidebar-community .comm-info { flex: 1; min-width: 0; }
.sidebar-community .comm-name { font-size: 0.82rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-community .comm-sub { font-size: 0.7rem; color: var(--text-muted); }
.sidebar-top-post {
    display: flex; gap: 10px; padding: 8px 0; cursor: pointer; text-decoration: none;
    color: var(--text); border-bottom: 1px solid var(--border); transition: var(--transition);
}
.sidebar-top-post:last-child { border-bottom: none; }
.sidebar-top-post:hover { opacity: 0.85; }
.sidebar-top-post .tp-num { font-size: 1.3rem; font-weight: 700; color: var(--accent); flex-shrink: 0; width: 28px; }
.sidebar-top-post .tp-title {
    font-size: 0.78rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden;
}

/* Post card */
.post-card {
    background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border);
    overflow: hidden; transition: var(--transition); position: relative;
}
.post-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); background: var(--bg-card-hover); }
.post-card-inner { display: flex; gap: 0; }
.post-vote {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 14px 10px; flex-shrink: 0; min-width: 52px; background: rgba(0,0,0,0.15); user-select: none;
}
.vote-btn {
    width: 30px; height: 30px; border-radius: 50%; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; font-size: 1.1rem; transition: var(--transition);
    display: flex; align-items: center; justify-content: center;
}
.vote-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }
.vote-btn.voted-up { color: var(--green); background: var(--green-soft); }
.vote-btn.voted-down { color: var(--red); background: var(--red-soft); }
.vote-count { font-weight: 600; font-size: 0.85rem; color: var(--text); min-width: 24px; text-align: center; }
.post-body { flex: 1; min-width: 0; padding: 14px 14px 14px 4px; display: flex; flex-direction: column; gap: 8px; }
.post-header-row { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: var(--text-muted); flex-wrap: wrap; }
.post-author-avatar,
.post-author-avatar img,
.comment-avatar,
.user-avatar {
    width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0; object-fit: cover;
    background: var(--bg-elevated); display: block;
}
.post-author-avatar-lg,
.post-author-avatar-lg img { width: 40px; height: 40px; }
.post-author-avatar-link { display: flex; flex-shrink: 0; line-height: 0; }
.post-author-avatar.anon { opacity: 0.7; }
.logo-img { width: 34px; height: 34px; border-radius: 10px; object-fit: contain; }
.post-author-name { font-weight: 500; color: var(--text-secondary); cursor: pointer; text-decoration: none; }
.post-author-name:hover { color: var(--accent); }
.author-rating-badge {
    font-size: 0.68rem; color: var(--accent); background: var(--accent-soft);
    padding: 1px 6px; border-radius: 10px; font-weight: 600; white-space: nowrap;
}
.author-rating-badge i { font-size: 0.6rem; margin-right: 2px; }
.post-dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-muted); }
.post-title {
    font-size: 1.05rem; font-weight: 600; line-height: 1.35; color: #fff;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.post-title a { color: inherit; text-decoration: none; }
.post-title a:hover { color: var(--accent); }
.post-image-wrap { border-radius: var(--radius); overflow: hidden; max-height: 420px; position: relative; background: #0a0a0c; }
.post-image-wrap img { width: 100%; height: auto; max-height: 420px; object-fit: contain; display: block; }
.post-image-wrap .img-badge {
    position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.7); color: #fff;
    border-radius: 6px; padding: 3px 8px; font-size: 0.7rem; display: flex; align-items: center; gap: 4px;
}
.post-text-preview {
    font-size: 0.88rem; color: var(--text-secondary); line-height: 1.5;
    display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.post-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.post-tag { font-size: 0.72rem; color: var(--blue); cursor: pointer; text-decoration: none; transition: var(--transition); }
.post-tag:hover { color: #7ab8e8; text-decoration: underline; }
.post-tag::before { content: '#'; }
.post-actions-row { display: flex; align-items: center; gap: 16px; font-size: 0.78rem; color: var(--text-muted); flex-wrap: wrap; }
.post-action {
    display: flex; align-items: center; gap: 5px; cursor: pointer; transition: var(--transition);
    padding: 6px 10px; border-radius: 16px; border: none; background: transparent;
    color: var(--text-muted); font-family: inherit; font-size: 0.78rem; text-decoration: none;
}
.post-action:hover { background: rgba(255,255,255,0.04); color: #fff; }
.post-action.saved, .post-action.saved i { color: var(--accent); }

/* Mobile nav & drawer */
.mobile-bottom-nav {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 300;
    background: rgba(20,20,22,0.92); backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-strong);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: center; height: var(--bottom-nav-h);
}
.mobile-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    color: var(--text-muted); text-decoration: none; cursor: pointer; font-size: 0.6rem; font-weight: 500;
    transition: var(--transition); border: none; background: transparent; font-family: inherit;
    padding: 4px 8px; border-radius: 12px; min-width: 48px;
}
.mobile-nav-item i { font-size: 1.3rem; }
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item.create-btn {
    background: var(--accent); color: #fff; border-radius: 50%; width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center; padding: 0; font-size: 1.2rem;
}
.sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 350; background: rgba(0,0,0,0.6);
    opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s;
}
.sidebar-overlay.show { opacity: 1; visibility: visible; }
.mobile-sidebar-drawer {
    display: none; position: fixed; top: 0; right: 0; bottom: 0;
    width: min(85vw, 360px); z-index: 360; background: var(--bg-card);
    border-left: 1px solid var(--border-strong); transform: translateX(105%);
    transition: transform 0.32s cubic-bezier(0.32,0.72,0,1); overflow-y: auto;
    padding: 16px; flex-direction: column; gap: 16px;
}
.mobile-sidebar-drawer.show { transform: translateX(0); }
.sidebar-drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.sidebar-drawer-header h3 { font-size: 1rem; font-weight: 600; }
.sidebar-drawer-close {
    width: 34px; height: 34px; border-radius: 50%; border: none;
    background: rgba(255,255,255,0.06); color: #fff; cursor: pointer; font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
}

/* Modals & toast */
.modal-overlay {
    position: fixed; inset: 0; z-index: 400; background: rgba(0,0,0,0.7);
    backdrop-filter: blur(2px); opacity: 0; visibility: hidden; transition: 0.25s;
}
.modal-overlay.show { opacity: 1; visibility: visible; }
.quick-modal {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 410;
    background: var(--bg-elevated); border-radius: 20px 20px 0 0; padding: 20px;
    transform: translateY(105%); transition: 0.3s cubic-bezier(0.32,0.72,0,1);
    max-height: 80vh; overflow-y: auto; border-top: 1px solid var(--border-strong);
}
.quick-modal.show { transform: translateY(0); }
.quick-modal-handle {
    width: 36px; height: 4px; background: rgba(255,255,255,0.2);
    border-radius: 4px; margin: 0 auto 14px;
}
.toast {
    position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--bg-elevated); border: 1px solid var(--border-strong); border-radius: 30px;
    padding: 10px 20px; font-size: 0.82rem; z-index: 500; opacity: 0; pointer-events: none;
    transition: 0.3s; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 8px; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast i { color: var(--green); }

/* Buttons */
.btn {
    padding: 8px 16px; border-radius: 20px; font-size: 0.85rem; font-weight: 500;
    border: none; cursor: pointer; transition: var(--transition); font-family: inherit;
    display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; text-decoration: none;
}
.btn-primary, .btn.accent { background: var(--accent); color: #fff; }
.btn-primary:hover, .btn.accent:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* Site footer */
.site-footer { padding: 24px 16px; text-align: center; font-size: 0.72rem; color: var(--text-muted); }
.empty-state { color: var(--text-muted); padding: 40px; text-align: center; }
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* Admin shared */
body.admin-body { background: var(--admin-bg); }
.admin-header .header-admin-label {
    background: var(--accent-soft); color: var(--accent); font-size: 0.75rem;
    padding: 4px 10px; border-radius: 20px; font-weight: 500; display: none;
}
.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.admin-sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0; width: 260px;
    background: var(--admin-card); border-right: 1px solid var(--border);
    overflow-y: auto; z-index: 150; padding: 16px 0; display: flex; flex-direction: column;
}
.sidebar-nav-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 20px; margin: 2px 8px;
    border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 0.88rem;
    cursor: pointer; transition: var(--transition); border: none; background: transparent;
    width: calc(100% - 16px); font-family: inherit; text-decoration: none;
}
.sidebar-nav-item i { width: 20px; text-align: center; font-size: 1rem; }
.sidebar-nav-item:hover { background: rgba(255,255,255,0.03); color: #fff; }
.sidebar-nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.sidebar-section-title {
    padding: 16px 20px 6px; font-size: 0.7rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted);
}
.admin-main { margin-left: 260px; padding: 24px 20px 40px; max-width: calc(1440px - 260px); }

@media (max-width: 1100px) {
    .sidebar { display: none; }
    .mobile-sidebar-drawer { display: flex; }
    .sidebar-overlay { display: block; }
    .header-btn-sidebar-toggle { display: flex !important; }
}
@media (min-width: 1101px) {
    .mobile-sidebar-drawer { display: none !important; }
    .header-btn-sidebar-toggle { display: none !important; }
}
@media (max-width: 768px) {
    .header-search { max-width: 100%; flex: 1 1 160px; }
    .header-btn-create span { display: none; }
    .header-btn-create { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 50%; }
    .header-logo { font-size: 1.15rem; }
    .mobile-bottom-nav { display: flex; }
    body { padding-bottom: var(--bottom-nav-h); }
}
@media (max-width: 1024px) {
    .admin-sidebar { transform: translateX(-100%); transition: transform 0.3s ease; z-index: 260; }
    .admin-sidebar.mobile-open { transform: translateX(0); }
    .admin-main { margin-left: 0; max-width: 100%; }
    .admin-header .header-admin-label { display: inline-flex; }
    .admin-mobile-nav { display: flex; }
    body.admin-body { padding-bottom: var(--bottom-nav-h); }
    #sidebarToggleBtn { display: flex !important; }
}
