:root {
    --bg: #f5f5f5;
    --panel: #ffffff;
    --accent: #111;
    --gap: 16px;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

html, body {
    overflow-x: hidden;
    width: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--accent);
}

/* ===== Mobile Header ===== */

.mobile-header { display: none; }

@media (max-width: 768px) {
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: var(--panel);
        box-shadow: var(--shadow);
        z-index: 1000;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
    }

    .site-title {
        font-size: 14px;
        font-weight: 700;
        letter-spacing: 1.5px;
    }
}

/* ===== Burger Menu ===== */

.burger {
    width: 28px;
    height: 24px;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.burger span,
.burger span::before,
.burger span::after {
    display: block;
    width: 100%;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    transition: all .3s;
}

.burger span::before,
.burger span::after {
    content: '';
    position: absolute;
}

.burger span::before { top: 0; }
.burger span::after { bottom: 0; }

/* ===== Layout ===== */

.layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    min-height: 100vh;
}

/* ===== Sidebar ===== */

.sidebar {
    background: var(--panel);
    padding: 32px 24px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    min-height: 100vh;
    height: auto;
    overflow: visible;
    display: flex;
    flex-direction: column;
}

.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(to bottom, transparent, rgba(0,0,0,.05) 20%, rgba(0,0,0,.05) 80%, transparent);
}

.logo {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 32px;
    flex-shrink: 0;
}

/* Auth Block */
.auth-block {
    padding: 16px;
    background: #f9f9f9;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: white;
    border-radius: 8px;
    font-weight: 500;
}

.user-icon {
    font-size: 20px;
}

.user-name {
    color: #111;
}

.auth-btn {
    display: block;
    text-align: center;
    padding: 10px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s;
}

.auth-btn-login {
    background: #111;
    color: white;
}

.auth-btn-login:hover {
    background: #333;
}

.auth-btn-signup {
    background: white;
    color: #111;
    border: 2px solid #111;
}

.auth-btn-signup:hover {
    background: #f5f5f5;
}

.auth-btn-logout {
    background: #dc3545;
    color: white;
}

.auth-btn-logout:hover {
    background: #c82333;
}

.menu,
.tags-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu li,
.tags-menu li { 
    margin-bottom: 6px;
}

.menu li:last-child,
.tags-menu li:last-child {
    margin-bottom: 0;
}

.menu a,
.tags-menu a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--accent);
    font-weight: 600;
    transition: all .2s ease;
    border: none;
    background: #f7f7f7;
    box-shadow: 0 2px 6px rgba(0,0,0,.03);
}

.menu a:hover,
.tags-menu a:hover {
    background: #ededed;
    transform: translateX(1px);
    box-shadow: 0 3px 10px rgba(0,0,0,.05);
}

.menu a.active,
.tags-menu a.active {
    background: linear-gradient(135deg, #111 0%, #333 100%);
    color: white;
    box-shadow: 0 6px 16px rgba(0,0,0,.18);
    border-color: #111;
}

.menu a.active::before,
.tags-menu a.active::before {
    display: none;
}

.tag-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.menu-section {
    margin-bottom: 32px;
}

.menu-section h3 {
    font-size: 13px;
    font-weight: 700;
    margin: 0 0 16px 0;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding-bottom: 8px;
    border-bottom: 2px solid rgba(0,0,0,.06);
}

.tags-menu {
    /* убран лимит высоты, список раскрывается полностью */
    padding-right: 8px;
}

.tags-menu::-webkit-scrollbar {
    width: 6px;
}

.tags-menu::-webkit-scrollbar-track {
    background: transparent;
}

.tags-menu::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,.1);
    border-radius: 3px;
}

.tags-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,.2);
}

.tag-count {
    background: rgba(0,0,0,.08);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    font-weight: 700;
    min-width: 30px;
    text-align: center;
    letter-spacing: 0.3px;
}

.menu a:hover .tag-count {
    background: rgba(0,0,0,.12);
}

.menu a.active .tag-count {
    background: rgba(255,255,255,.25);
    color: white;
}

@media (max-width: 768px) {
    .layout { grid-template-columns: 1fr; }

    .content h1 {
        text-align: center;
        margin-top: 0;
    }

    .content h1 .content-count {
        display: block;
        margin-top: 0.35em;
        text-align: center;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -410px;
        width: 390px;
        height: 100vh;
        transition: left .3s ease;
        z-index: 999;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.open { left: 0; }

    body.menu-open {
        overflow: hidden;
    }

    .pagination {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        margin: 24px 0;
        padding-bottom: 8px;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
    }

    .pagination::-webkit-scrollbar {
        height: 4px;
    }

    .page-link {
        padding: 8px 12px;
        font-size: 14px;
        flex-shrink: 0;
    }

    .page-dots {
        padding: 8px 6px;
        flex-shrink: 0;
    }
}

@media (min-width: 769px) and (max-width: 1200px) {
    .layout {
        grid-template-columns: 280px 1fr;
    }

    .sidebar {
        padding: 24px 16px;
    }
}

/* ===== Content ===== */

.content { 
    padding: 32px;
}

@media (max-width: 768px) {
    .content {
        padding: 120px 32px 32px 32px;
    }
}

main {
    max-width: 2000px;
    margin: 0 auto;
}

/* ===== Gallery (Masonry) ===== */

.gallery {
    column-count: 5;
    column-gap: var(--gap);
}

@media (max-width: 1800px) { .gallery { column-count: 5; } }
@media (max-width: 1500px) { .gallery { column-count: 4; } }
@media (max-width: 1200px) { .gallery { column-count: 3; } }
@media (max-width: 900px)  { .gallery { column-count: 2; } }
@media (max-width: 600px)  { .gallery { column-count: 1; } }
@media (min-width: 769px) and (max-width: 1200px) { .gallery { column-count: 3; } }

/* ===== Item ===== */

.item {
    position: relative;
    break-inside: avoid;
    margin-bottom: var(--gap);
    background: var(--panel);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: default;
    /* фиксируем слой, чтобы исключить подёргивания при hover */
    transform: translateZ(0);
}

.item img {
    width: 100%;
    max-width: 100%;
    height: auto;
    display: block;
}

.item video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity .3s;
    pointer-events: none;
}

/* Иконка видео на миниатюрах */
.item-video-icon {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    z-index: 2;
}

/* Video blur overlay */
.video-blur {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
    .item:hover .video-blur {
        opacity: 1;
        pointer-events: all;
    }
}

/* На touch-устройствах показываем блюр при тапе (смартфоны и планшеты) */
@media (hover: none) and (pointer: coarse) {
    .video-blur {
        opacity: 0;
    }

    /* Disable iOS synthetic hover: blur must be controlled only by JS class. */
    .item:hover .video-blur {
        opacity: 0;
        pointer-events: none;
    }
    
    .item.show-blur .video-blur {
        opacity: 1;
        pointer-events: all;
    }
    
    .item.show-blur.video-playing img {
        opacity: 0;
    }
    
    .item.show-blur video {
        opacity: 1;
        z-index: 0;
    }
}

.video-buttons {
    text-align: center;
}

.join-link {
    display: inline-block;
    padding: 12px 24px;
    background: linear-gradient(135deg, #fff 0%, #f1f1f1 100%);
    color: #111;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.2s;
    border: 1px solid #e0e0e0;
    box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.join-link:hover {
    background: #000;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.18);
}

@media (max-width: 600px) {
    .item {
        width: 100%;
        max-width: 100%;
        padding: 0;
    }
    
    .item img {
        max-width: 100%;
        width: 100%;
        height: auto;
    }
}

/* ===== Pagination ===== */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 40px 0;
    flex-wrap: wrap;
}

.page-link {
    display: inline-block;
    padding: 10px 16px;
    background: var(--panel);
    border-radius: 8px;
    text-decoration: none;
    color: var(--accent);
    font-weight: 500;
    transition: all .2s;
    box-shadow: var(--shadow);
}

.page-link:hover {
    background: var(--accent);
    color: white;
}

.page-link.active {
    background: var(--accent);
    color: white;
}

.page-link.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-dots {
    padding: 10px 8px;
    color: #999;
}

/* ===== Lightbox ===== */

.lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

/* Модал смены пароля (переиспользуем стили модалки лайтксбокса) */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    z-index: 11000;
}

.modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 520px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    position: relative;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.modal-header h3 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

.modal-body .form-group {
    margin-bottom: 16px;
}

.modal-body label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
}

.modal-body .input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.modal-footer {
    margin-top: 12px;
    text-align: right;
}

.modal-footer .btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: #111;
    color: #fff;
    cursor: pointer;
}


.lightbox-content {
    position: relative;
    width: 90%;
    height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-media {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-media img,
.lightbox-media video {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 40px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 50px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-prev {
    left: 20px;
}

.lightbox-next {
    right: 20px;
}

.item-clickable {
    cursor: pointer;
}

.item-clickable:hover {
    /* Без масштабирования, чтобы не было смещения masonry */
    transform: none;
}
