/* Instagram Profile — Dark Clone v2 (Closer layout) */
:root {
    --bg: #000000;
    --panel: #0a0a0a;
    --fg: #f5f5f5;
    --muted: #a1a1aa;
    --line: #262626;
    --soft: #111111;
}

* {
    box-sizing: border-box
}

html, body {
    height: 100%;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--fg);
    background: var(--bg);
    position: relative;
    width: 100%;
    max-width: 100vw;
}

.app {
    display: grid;
    grid-template-columns: 244px 1fr;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    border-right: 1px solid var(--line);
    padding: 20px 12px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar-close {
    display: none;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--fg);
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    z-index: 10;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
}

.sidebar-close:hover {
    background: var(--soft);
}

.sidebar-close:active {
    transform: scale(0.95);
}

.brand {
    padding: 6px 8px 22px
}

.brand img {
    height: 28px;
    filter: invert(1) brightness(2);
}

.menu {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 70px);
}

.menu .item {
    margin-bottom: 17px;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 12px;
    border-radius: 10px;
    color: #eaeaea;
    text-decoration: none;
    cursor: pointer;
    position: relative;
}

.menu .item:hover {
    background: #111;
}

.menu .item.active {
    background: #101010;
}

.menu .item .avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--line)
}

.menu .badge {
    position: absolute;
    right: 12px;
    background: #ef4444;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 999px;
}

.menu .spacer {
    flex: 1 1 auto;
}

/* Main */
.main {
    display: flex;
    justify-content: center;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

.main-inner {
    width: 100%;
    max-width: 975px;
    padding: 24px 20px 80px;
    box-sizing: border-box;
}

/* Profile header */
.profile {
    display: grid;
    grid-template-columns: 214px 1fr;
    gap: 30px;
    align-items: center;
    margin: 6px 0 16px;
}

.avatar-wrap {
    position: relative;
    width: 168px;
    height: 168px;
    border-radius: 50%;
    padding: 0;
    background: transparent;
    margin: 0 auto;
    cursor: pointer;
}

.avatar-wrap.has-story {
    padding: 3px;
    background: linear-gradient(45deg, #f99, #ffb, #9cf, #f9f);
}

.avatar-wrap img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    background: #222;
}

.avatar-wrap.has-story img {
    border: 4px solid var(--bg);
}

.avatar-wrap .story-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 6px;
    border-radius: 10px;
    border: 2px solid var(--bg);
    z-index: 10;
}

.avatar-wrap .note {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f1f1f;
    color: #ddd;
    border: 1px solid #333;
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}

.info {
    min-width: 0;
}

.userline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.userline .left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.username {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.verified {
    color: #3ea6ff;
    font-size: 18px;
}

.actions {
    display: flex;
    gap: 8px;
}

.btn {
    background: #262626;
    color: #eee;
    border: 1px solid #353535;
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.btn.ghost {
    background: transparent;
}

.icon-btn {
    background: transparent;
    border: 1px solid #2a2a2a;
    padding: 8px 10px;
    border-radius: 8px;
    color: #e5e5e5;
    font-size: 16px;
    cursor: pointer;
}

.stats {
    list-style: none;
    padding: 0;
    margin: 8px 0 12px;
    display: flex;
    gap: 36px;
    color: #e5e5e5;
    font-size: 14px;
}

.stats b {
    font-weight: 700;
}

.bio {
    font-size: 14px;
    line-height: 1.5;
}

.bio .name {
    font-weight: 600;
}

.bio .link a {
    color: #a6d1ff;
    text-decoration: none;
}

.bio .link i {
    margin-right: 6px;
}

/* Highlights */
.highlights {
    display: grid;
    grid-template-columns: 40px 1fr 40px;
    align-items: center;
    gap: 8px;
    padding: 14px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin: 12px 0 8px;
}

.hl-nav {
    background: transparent;
    border: 0;
    color: #bdbdbd;
    font-size: 16px;
    cursor: pointer;
}

.hl-row {
    display: flex;
    gap: 22px;
    overflow: hidden;
}

.highlight {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 86px;
}

.highlight .circle {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    padding: 2px;
    background: #ffffff;
    border: 1px solid #2b2b2b;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.highlight .ring {
    background: #FFF
}

.highlight .circle img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #000;
}

.highlight span {
    margin-top: 8px;
    font-size: 12px;
    color: #cfcfcf;
}

.highlight .dashed {
    border: 2px dashed #3a3a3a;
    background: transparent;
    color: #cfcfcf;
}

.highlight.new i {
    font-size: 18px;
}

/* Tabs */
.tabs {
    display: flex;
    justify-content: center;
    gap: 28px;
    padding: 16px 0 10px;
}

.tab {
    background: transparent;
    border: 0;
    color: #cfcfcf;
    font-size: 16px;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: #fff;
    border-color: #fff;
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
}

.post {
    position: relative;
    background: #ffffff;
    aspect-ratio: 1/1;
    overflow: hidden;
    cursor: pointer;
}

.post img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .2s ease;
}

.post:hover img {
    transform: scale(1.02);
}

.pin-icon {
    position: absolute;
    top: 6px;
    right: 6px;
    background: #0b0b0b;
    border: 1px solid #1e1e1e;
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 12px;
}

/* Chat FAB */
.chat-fab {
    position: fixed;
    right: 16px;
    bottom: 16px;
    background: #0e0e0e;
    border: 1px solid #242424;
    padding: 12px 14px;
    border-radius: 999px;
    color: #eaeaea;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}

.chat-fab .badge {
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 999px;
}

.chat-fab .mini-avatars {
    display: flex;
}

.chat-fab .mini-avatars img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 1px solid #333;
    margin-left: -6px;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1000;
    background: #0e0e0e;
    border: 1px solid #242424;
    padding: 10px 12px;
    border-radius: 8px;
    color: #eaeaea;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .4);
}

.mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-menu-overlay.show {
    display: block;
    opacity: 1;
}

/* Responsive */
@media (max-width: 1100px) {
    .app {
        grid-template-columns: 72px 1fr;
    }

    .menu .item span {
        display: none;
    }

    .brand img {
        height: 28px;
    }
}

@media (max-width: 768px) {
    /* Mobile Menu */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .app {
        grid-template-columns: 1fr;
        min-height: 100vh;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        width: 280px;
        max-width: 85vw;
        z-index: 1001;
        background: var(--bg);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.5);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 20px 12px 12px;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-close {
        display: flex;
    }

    .menu {
        padding: 20px 0;
        height: auto;
        min-height: calc(100vh - 40px);
    }

    .menu .item {
        margin-bottom: 8px;
        font-size: 15px;
        padding: 14px 16px;
        min-height: 48px;
        -webkit-tap-highlight-color: transparent;
    }

    .menu .item span {
        display: inline;
    }

    .menu .item i {
        width: 24px;
        text-align: center;
    }

    /* Main Content */
    .main {
        width: 100%;
        overflow-x: hidden;
    }

    .main-inner {
        padding: 70px 16px 100px;
        max-width: 100%;
        width: 100%;
    }

    /* Profile Section */
    .profile {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
        gap: 24px;
        margin: 0 0 24px;
        padding: 0;
    }

    .avatar-wrap {
        width: 110px;
        height: 110px;
        flex-shrink: 0;
    }

    .info {
        width: 100%;
        text-align: center;
        max-width: 100%;
    }

    .userline {
        flex-direction: column;
        align-items: center;
        gap: 12px;
        margin-bottom: 16px;
        width: 100%;
    }

    .userline .left {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .username {
        font-size: 20px;
        word-break: break-word;
    }

    .verified {
        font-size: 18px;
        flex-shrink: 0;
    }

    .stats {
        flex-wrap: wrap;
        justify-content: center;
        gap: 24px;
        font-size: 14px;
        margin: 16px 0;
        width: 100%;
    }

    .stats li {
        flex: 0 0 auto;
        text-align: center;
        white-space: nowrap;
    }

    .bio {
        text-align: center;
        font-size: 14px;
        line-height: 1.6;
        width: 100%;
        word-wrap: break-word;
    }

    .bio .name {
        margin-bottom: 4px;
    }

    .bio > div {
        margin-bottom: 6px;
    }

    /* Highlights */
    .highlights {
        padding: 16px 0;
        margin: 20px 0;
        position: relative;
    }

    .hl-nav {
        display: none;
    }

    .hl-row {
        padding: 0 16px;
        gap: 16px;
        -webkit-overflow-scrolling: touch;
    }

    .highlight {
        width: 70px;
        flex-shrink: 0;
    }

    .highlight .circle {
        width: 64px;
        height: 64px;
    }

    .highlight span {
        font-size: 11px;
        margin-top: 6px;
        line-height: 1.3;
    }

    /* Tabs */
    .tabs {
        gap: 0;
        padding: 16px 0 12px;
        justify-content: center;
        border-bottom: 1px solid var(--line);
        margin-bottom: 4px;
    }

    .tab {
        font-size: 16px;
        padding: 10px 16px;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
    }

    /* Grid */
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 2px;
        margin: 0;
    }

    .post {
        min-height: 0;
    }

    /* Chat FAB */
    .chat-fab {
        right: 16px;
        bottom: 80px;
        padding: 12px 16px;
        font-size: 13px;
        min-height: 44px;
        -webkit-tap-highlight-color: transparent;
        z-index: 100;
    }

    .chat-fab .mini-avatars img {
        width: 20px;
        height: 20px;
    }

    /* Story Viewer Mobile */
    .story-viewer {
        padding: 0;
        background: rgba(0, 0, 0, 1);
    }
    
    .story-inner {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        box-shadow: none;
    }
    
    .story-top {
        padding: 12px 16px 0;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
    }
    
    .story-head {
        padding: 10px 0 8px;
    }
    
    .story-name {
        font-size: 14px;
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .story-time {
        font-size: 11px;
    }
    
    .story-close {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        font-size: 18px;
        flex-shrink: 0;
    }
    
    .story-media {
        padding: 8px;
        flex: 1;
        min-height: 0;
    }
    
    .story-caption {
        padding: 10px 16px 14px;
        font-size: 13px;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
    }
    
    .story-arrow {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .mobile-menu-toggle {
        top: 12px;
        left: 12px;
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }

    .main-inner {
        padding: 64px 12px 90px;
    }

    .profile {
        gap: 20px;
        margin: 0 0 20px;
    }

    .avatar-wrap {
        width: 96px;
        height: 96px;
    }

    .username {
        font-size: 18px;
    }

    .verified {
        font-size: 16px;
    }

    .stats {
        gap: 20px;
        font-size: 13px;
        margin: 14px 0;
    }

    .stats li {
        font-size: 13px;
    }

    .bio {
        font-size: 13px;
        line-height: 1.6;
    }

    .highlights {
        padding: 14px 0;
        margin: 18px 0;
    }

    .hl-row {
        padding: 0 12px;
        gap: 14px;
    }

    .highlight {
        width: 64px;
    }

    .highlight .circle {
        width: 58px;
        height: 58px;
    }

    .highlight span {
        font-size: 10px;
        margin-top: 5px;
    }

    .tabs {
        padding: 14px 0 10px;
    }

    .tab {
        font-size: 15px;
        padding: 8px 12px;
        min-height: 40px;
    }

    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 2px;
    }

    .chat-fab {
        right: 12px;
        bottom: 70px;
        padding: 10px 14px;
        font-size: 12px;
        min-height: 40px;
    }

    .chat-fab .mini-avatars img {
        width: 18px;
        height: 18px;
    }
}

@media (max-width: 360px) {
    .main-inner {
        padding: 60px 8px 85px;
    }

    .avatar-wrap {
        width: 88px;
        height: 88px;
    }

    .username {
        font-size: 17px;
    }

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

    .bio {
        font-size: 12px;
    }

    .highlight {
        width: 60px;
    }

    .highlight .circle {
        width: 54px;
        height: 54px;
    }

    .tab {
        font-size: 14px;
        padding: 8px 10px;
    }
}

/* Highlights - Improved scrolling version */
.highlights {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 0;
    overflow: hidden;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin: 12px 0 8px;
}

.hl-row {
    display: flex;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 22px;
    flex: 1;
    padding: 0 8px;
}

.hl-row::-webkit-scrollbar {
    display: none;
}

.highlight {
    flex: 0 0 auto;
    width: 86px;
    margin: 0;
    text-align: center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.highlight .circle {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto;
    border: 3px solid #444;
    transition: transform .2s;
    padding: 2px;
    background: #fff;
    border: 1px solid #2b2b2b;
    display: grid;
    place-items: center;
}

.highlight .circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid #000;
}

.highlight span {
    display: block;
    margin-top: 8px;
    color: #cfcfcf;
    font-size: 12px;
}

.highlight:hover .circle {
    transform: scale(.97);
}

.hl-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.18);
    color: #fff;
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.hl-nav.left {
    left: 8px;
}

.hl-nav.right {
    right: 8px;
}

.hl-nav:active {
    transform: translateY(-50%) scale(.96);
}

.story-viewer{
    position:fixed; inset:0; background:rgba(0,0,0,.95);
    display:none; align-items:center; justify-content:center; z-index:9999;
    overflow: hidden;
}
.story-viewer.show{ display:flex }

.story-inner{
    position:relative; width:min(420px,92vw); height:min(740px,92vh);
    background:#FFF; border-radius:16px; overflow:hidden;
    box-shadow:0 10px 40px rgba(0,0,0,.6); display:flex; flex-direction:column;
    max-width: 100vw;
    max-height: 100vh;
}

.story-top{ position:relative; padding:10px 12px 0 12px; z-index:3 }
.story-bars{ display:flex; gap:6px; padding-bottom:10px }
.story-bar{ flex:1; height:3px; background:rgba(255,255,255,.25); border-radius:2px; overflow:hidden }
.story-bar-fill{ width:0%; height:100%; background:#fff; transition:width linear }

.story-head{ display:flex; align-items:center; gap:10px; padding:8px 0 6px }
.story-avatar{ width:28px; height:28px; border-radius:50%; background:#fff; object-fit:cover; flex-shrink:0 }
.story-meta{ display:flex; flex-direction:column; line-height:1.1; min-width:0; flex:1 }
.story-name{ color:#000; font-weight:600; font-size:14px; word-break:break-word; overflow:hidden; text-overflow:ellipsis }
.story-time{ color: rgba(0, 0, 0, 0.67); font-size:12px }

.story-close{
    margin-left:auto; width:34px; height:34px; border:none;
    background:var(--glass); color:#000; border-radius:50%;
    cursor:pointer; z-index:4; position:relative;
}

.story-media{ flex:1; display:grid; place-items:center; padding:8px 8px 0 8px; position: relative; overflow: hidden }
.story-media .story-image{
    width:100%;
    height:100%;
    max-width:100%;
    max-height:100%;
    object-fit:contain;
    display:block;
    background:#fff;
}
.story-media .story-image{
    position:absolute;
    inset:0;
}
.story-caption{
    padding:12px 14px 16px; color: #4b4b4b; font-size:14px; line-height:1.4;
    background:linear-gradient(0deg, rgba(0,0,0,.5), transparent);
}

.tap-zone{
    position:absolute; top:60px; bottom:0; width:50%; cursor:pointer; z-index:1;
}
.tap-zone.left{ left:0 } .tap-zone.right{ right:0 }

.story-arrow{
    position:absolute; top:50%; transform:translateY(-50%);
    width:38px; height:38px; border:none; border-radius:50%;
    background:rgb(0 0 0 / 18%); color:#fff; cursor:pointer; z-index:2; display:none;
}
.story-arrow.left{ left:8px } .story-arrow.right{ right:8px }
@media (min-width:768px){ .story-arrow{ display:inline-flex; align-items:center; justify-content:center } }

.story-rail{
    position:absolute; right:3vw; top:10vh; bottom:10vh;
    width:220px; display:none; gap:14px; flex-direction:column; z-index:5;
}
.story-rail .rail-card{
    width:100%; height:180px; background:#111; border-radius:14px; overflow:hidden;
    display:flex; align-items:center; justify-content:center; color:#fff;
}
@media (min-width:1200px){ .story-rail{ display:flex } }

/* Post Modal */
.post-modal{
    position:fixed; inset:0; background:rgba(0,0,0,.95);
    display:none; align-items:center; justify-content:center; z-index:9999;
    overflow: hidden;
}
.post-modal.show{ display:flex }

.post-modal-inner{
    position:relative; width:min(800px,95vw); height:min(90vh,95vh);
    background:#000; border-radius:16px; overflow:hidden;
    box-shadow:0 10px 40px rgba(0,0,0,.6); display:flex; flex-direction:column;
    max-width: 100vw;
    max-height: 100vh;
}

.post-modal-close{
    position:absolute; top:16px; right:16px; width:40px; height:40px;
    border:none; background:rgba(0,0,0,.5); color:#fff; border-radius:50%;
    cursor:pointer; z-index:10; display:flex; align-items:center; justify-content:center;
    font-size:20px; transition:background .2s;
}
.post-modal-close:hover{ background:rgba(0,0,0,.7) }

.post-modal-image{
    flex:1; display:flex; align-items:center; justify-content:center;
    padding:60px 20px 20px; overflow:hidden;
}
.post-modal-image img{
    max-width:100%; max-height:100%; object-fit:contain; display:block;
}
