:root {
  --bg-color: #080b12;
  --surface-color: #0f1623;
  --surface-hover: #151e2e;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 179, 237, 0.3);
  --text-main: #e8edf5;
  --text-muted: #8899b0;
  --text-dark: #4a5568;
  
  --accent-primary: #4fc3f7;
  --accent-secondary: #a78bfa;
  --accent-success: #34d399;
  --accent-danger: #f87171;
  
  --font-heading: 'Syne', sans-serif;
  --font-body: 'DM Sans', sans-serif;
  
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  
  --shadow-glow: 0 0 20px rgba(79, 195, 247, 0.1);
  --nav-width: 260px;
  --sidebar-width: 300px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  /* REMOVED: overflow-x: hidden — was blocking horizontal scroll context and interfering with touch scroll */
}

/* Ambient Background */
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
}
.ambient-blob {
  position: fixed; border-radius: 50%; filter: blur(100px); pointer-events: none; z-index: -1;
}
.blob-1 { width: 500px; height: 500px; background: rgba(79,195,247,0.05); top: -150px; left: -150px; }
.blob-2 { width: 600px; height: 600px; background: rgba(167,139,250,0.04); bottom: -200px; right: -200px; }

/* LAYOUT */
.app-container {
  display: flex;
  max-width: 1280px;
  margin: 0 auto;
  min-height: 100vh;
  /* Prevent horizontal overflow without blocking vertical scroll */
  overflow-x: clip;
}

.app-main {
  flex: 1;
  min-width: 0;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
}

.view { display: none; padding: 24px; animation: fadeIn 0.3s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* NAVIGATION (Desktop Left) */
.app-nav {
  width: var(--nav-width);
  padding: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  /* ADDED: prevent nav itself from being a scroll trap */
  overflow-y: auto;
}

.nav-brand {
  display: flex; align-items: center; gap: 12px; margin-bottom: 40px;
  font-family: var(--font-heading); font-size: 1.5rem; font-weight: 800;
}
.logo-mark {
  width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 1.1rem;
}

.nav-links { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: transparent; border: none; color: var(--text-main); font-family: var(--font-body);
  font-size: 1.1rem; font-weight: 600; border-radius: 99px; cursor: pointer; transition: 0.2s;
  text-align: left;
}
.nav-btn svg { width: 24px; height: 24px; opacity: 0.8; }
.nav-btn:hover { background: rgba(255, 255, 255, 0.05); }
.nav-btn.active { color: var(--accent-primary); background: rgba(79, 195, 247, 0.1); }
.nav-btn.active svg { opacity: 1; }

.nav-user-status { margin-top: auto; padding: 12px; }
.online-pill {
  display: inline-flex; align-items: center; gap: 8px; background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.2); padding: 8px 16px; border-radius: 99px;
  color: var(--accent-success); font-size: 0.85rem; font-weight: 600;
}
.online-dot { width: 8px; height: 8px; background: var(--accent-success); border-radius: 50%; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* SIDEBAR (Desktop Right) */
.app-sidebar {
  width: var(--sidebar-width);
  padding: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.widget-card {
  background: var(--surface-color); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px; margin-bottom: 20px;
}
.widget-title { font-family: var(--font-heading); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 16px; }

/* UTILS & INPUTS - iOS auto-zoom fix: minimum 16px font size */
.standard-input, .search-box input, .compose-input {
  font-size: 16px !important;
}

.standard-input {
  width: 100%; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 12px 16px; color: var(--text-main);
  font-family: var(--font-body); outline: none; transition: 0.2s;
}
.standard-input:focus { border-color: var(--border-glow); background: rgba(255, 255, 255, 0.06); }

.search-box { position: relative; width: 100%; margin-bottom: 24px; }
.search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); pointer-events: none; }
.search-box input { width: 100%; padding: 14px 16px 14px 44px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-color); border-radius: 99px; color: var(--text-main); outline: none; transition: 0.2s; }
.search-box input:focus { border-color: var(--border-glow); box-shadow: var(--shadow-glow); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none; border-radius: 99px; padding: 10px 24px; color: #fff;
  font-family: var(--font-heading); font-weight: 700; font-size: 0.9rem; cursor: pointer; transition: 0.2s;
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.1); box-shadow: var(--shadow-glow); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small { padding: 8px 16px; font-size: 0.8rem; }
.full-width { width: 100%; padding: 14px; font-size: 1rem; margin-top: 10px; }

.btn-cancel { background: transparent; border: none; color: var(--text-muted); padding: 10px 16px; cursor: pointer; font-weight: 600; transition: 0.2s; }
.btn-cancel:hover { color: var(--text-main); }
.btn-icon { background: transparent; border: none; color: var(--text-muted); cursor: pointer; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: 0.2s; }
.btn-icon:hover { background: rgba(255, 255, 255, 0.05); color: var(--text-main); }

.user-avatar {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
  display: flex; align-items: center; justify-content: center; font-family: var(--font-heading);
  font-weight: 700; font-size: 1rem; color: #fff; text-transform: uppercase;
}

/* COMPOSER */
.composer {
  background: var(--surface-color); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 16px; margin-bottom: 24px; transition: 0.3s;
}
.composer:focus-within { border-color: var(--border-glow); box-shadow: var(--shadow-glow); }
.composer-top { display: flex; gap: 16px; align-items: flex-start; }
.compose-input {
  flex: 1; background: transparent; border: none; color: var(--text-main); font-family: var(--font-body);
  resize: none; outline: none; padding-top: 8px; line-height: 1.5;
  transition: height 0.2s ease;
}
.compose-input::placeholder { color: var(--text-dark); }
.composer-extras {
  display: none; padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--border-color);
  animation: fadeIn 0.3s ease;
}
.composer-extras.active { display: block; }
.extras-inputs { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.extras-inputs input { width: 100%; background: transparent; border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 10px 14px; color: var(--text-main); outline: none; }
.extras-inputs input:focus { border-color: var(--accent-primary); }
.composer-footer { display: flex; justify-content: space-between; align-items: center; }
.composer-actions { display: flex; gap: 8px; }
.char-counter { font-size: 0.8rem; color: var(--text-muted); }

/* FEED POSTS */
.feed-container { display: flex; flex-direction: column; gap: 16px; }
.post-card { background: var(--surface-color); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 20px; transition: 0.2s; animation: fadeIn 0.4s ease; }
.post-card:hover { border-color: rgba(255, 255, 255, 0.15); }
.post-card.highlight { border-color: var(--accent-primary); box-shadow: var(--shadow-glow); }
.post-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.post-author-info { display: flex; gap: 12px; align-items: center; }
.post-meta { display: flex; flex-direction: column; }
.post-author-name { font-weight: 600; font-size: 1rem; }
.post-time { font-size: 0.8rem; color: var(--text-muted); }
.delete-btn { color: var(--text-dark); display: none; }
.delete-btn:hover { color: var(--accent-danger); background: rgba(248, 113, 113, 0.1); }
.post-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.post-tag { font-size: 0.75rem; background: rgba(167, 139, 250, 0.1); color: var(--accent-secondary); padding: 4px 10px; border-radius: 99px; }
.post-content { font-size: 1rem; line-height: 1.6; white-space: pre-wrap; word-break: break-word; margin-bottom: 16px; }
.post-content a { color: var(--accent-primary); text-decoration: none; }
.post-content a:hover { text-decoration: underline; }
.post-content .hashtag { color: var(--accent-secondary); font-weight: 500; }
.post-image { width: 100%; border-radius: var(--radius-md); margin-bottom: 16px; display: none; object-fit: cover; max-height: 400px; border: 1px solid var(--border-color); }

/* POST ACTIONS & PANELS */
.post-actions-bar { display: flex; justify-content: space-between; border-top: 1px solid var(--border-color); padding-top: 12px; }
.action-btn { display: flex; align-items: center; gap: 8px; background: transparent; border: none; color: var(--text-muted); font-size: 0.9rem; font-weight: 500; cursor: pointer; padding: 12px; border-radius: var(--radius-md); transition: 0.2s; }
.action-btn:hover { background: rgba(255, 255, 255, 0.05); color: var(--text-main); }
.action-btn.active { color: var(--accent-primary); background: rgba(79, 195, 247, 0.1); }
.action-btn svg { width: 18px; height: 18px; }

.panel { display: none; margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--border-color); animation: fadeIn 0.2s ease; }
.panel.active { display: block; }
.reactions-panel { display: flex; flex-wrap: wrap; gap: 8px; }
.reaction-btn { background: rgba(255,255,255,0.05); border: 1px solid transparent; font-size: 1.2rem; padding: 6px 12px; border-radius: 99px; cursor: pointer; transition: 0.2s; }
.reaction-btn:hover { transform: scale(1.1); background: rgba(255,255,255,0.1); }

.share-panel.active { display: flex; gap: 8px; }
.comments-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 16px;
}

.comment-item {
  display: flex;
  gap: 0;
  position: relative;
  padding-left: 16px;
}
.comment-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 31px;
  top: 44px;
  bottom: -4px;
  width: 2px;
  background: linear-gradient(to bottom, rgba(79,195,247,0.25), transparent);
}

.comment-avatar {
  width: 32px;
  height: 32px;
  font-size: 0.72rem;
  font-weight: 800;
  flex-shrink: 0;
  margin-right: 12px;
  margin-top: 4px;
  box-shadow: 0 0 12px rgba(79,195,247,0.2);
  border: 1.5px solid rgba(255,255,255,0.1);
}
.comment-bubble {
  background: linear-gradient(135deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  backdrop-filter: blur(8px);
  padding: 11px 16px 10px;
  border-radius: 4px 14px 14px 14px;
  flex: 1;
  border: 1px solid rgba(255,255,255,0.07);
  margin-bottom: 8px;
  transition: border-color 0.2s;
  animation: commentIn 0.25s ease both;
}
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.comment-author { font-weight: 600; font-size: 0.85rem; }
.comment-time { font-size: 0.75rem; color: var(--text-muted); }
.comment-text { font-size: 0.9rem; color: var(--text-main); }
.comment-composer { display: flex; gap: 12px; align-items: flex-end; }
.comment-composer textarea { min-height: 42px; }

/* EXPLORE & STATS VIEW */
.explore-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.stat-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
.stat-row:last-child { border-bottom: none; }
.stat-row span { color: var(--text-muted); }
.trending-item { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; cursor: pointer; transition: 0.2s; }
.trending-item:hover .trend-tag { color: var(--accent-primary); }
.trend-tag { font-weight: 600; color: var(--accent-secondary); }
.trend-count { color: var(--text-muted); font-size: 0.8rem; }

/* PROFILE VIEW */
.profile-header { text-align: center; margin-bottom: 32px; }
.profile-avatar { width: 80px; height: 80px; font-size: 2rem; margin: 0 auto 16px; }
.profile-header h2 { font-family: var(--font-heading); font-size: 1.8rem; margin-bottom: 4px; }
.profile-sub { color: var(--text-muted); font-size: 0.9rem; }
.profile-settings { max-width: 400px; margin: 0 auto; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }
.captcha-box { background: rgba(79, 195, 247, 0.05); border: 1px solid rgba(79, 195, 247, 0.2); border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px; }
.captcha-box label { font-weight: 600; color: var(--accent-primary); }

/* TOAST */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--surface-color);
  border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 14px 20px;
  display: flex; align-items: center; gap: 12px; font-size: 0.9rem; z-index: 1000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); transform: translateY(100px); opacity: 0;
  transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.toast.show { transform: translateY(0); opacity: 1; }

/* SKELETON */
.skel { background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

.mobile-header { display: none; }
.hidden-mobile { display: block; }


/* ========================================================= */
/* MOBILE RESPONSIVE — SCROLL-FRIENDLY REWRITE               */
/* ========================================================= */
@media (max-width: 860px) {

  /* 1. Global resets — NO overflow blocking, NO overscroll trapping */
  html {
    /* Allow normal browser scroll everywhere */
    overflow-y: auto;
  }

  body {
    /* Do NOT set overflow-x: hidden here — it creates a new stacking context
       that can block touch-scroll on iOS. Use clip on the container instead. */
    overflow-x: clip;
    width: 100%;
    /* REMOVED: overscroll-behavior-y: contain — was preventing natural scroll momentum */
  }

  .app-container {
    flex-direction: column;
    width: 100%;
    min-height: auto;
    overflow-x: clip;
  }

  .hidden-mobile { display: none !important; }

  /* 2. Main content — natural document flow, not height-constrained */
  .app-main {
    border-left: none;
    border-right: none;
    padding-top: 60px;   /* Offset for fixed header */
    padding-bottom: 80px; /* Offset for fixed bottom nav + safe area */
    width: 100%;
    /* REMOVED: min-height: 100vh — was fighting natural content height and scroll */
  }

  .view {
    padding: 16px 12px;
    /* REMOVED: min-height: calc(100vh - 180px) — forces scroll context issues */
  }

  /* 3. Fixed top header — pointer-events none on backdrop so touches pass through */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 60px;
    background: rgba(8, 11, 18, 0.92);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border-color);
    /* Ensure touches on header don't bleed through */
    touch-action: none;
  }

  .mobile-header h1 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    flex: 1;
    text-align: center;
    margin: 0;
  }

  /* 4. Fixed bottom nav — allow-touch on nav buttons, not the whole bar */
  .app-nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    width: 100%;
    flex-direction: row;
    align-items: center;
    /* Use safe-area for notched phones */
    padding: 8px 12px env(safe-area-inset-bottom, 8px);
    background: rgba(15, 22, 35, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    transition: transform 0.3s ease-in-out;
    /* CRITICAL: prevent nav bar from intercepting page scroll */
    touch-action: none;
    overflow: visible;
  }

  .app-nav.nav-hidden {
    transform: translateY(100%);
  }

  .nav-brand { display: none; }

  .nav-links {
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    gap: 0;
    flex: unset;
  }

  .nav-btn {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    flex: 1;
    justify-content: center;
    align-items: center;
    background: transparent !important;
    border-radius: var(--radius-sm);
    height: auto;
    /* Allow tap but not scroll interception */
    touch-action: manipulation;
  }

  .nav-btn span { font-size: 0.7rem; font-weight: 500; }
  .nav-btn svg { width: 24px; height: 24px; }
  .nav-btn.active { background: transparent !important; }
  .nav-btn.active span { color: var(--accent-primary); }
  .nav-btn.active svg {
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(79,195,247,0.4));
  }

  /* 5. Feed & cards */
  .explore-grid { grid-template-columns: 1fr; }
  .post-card { padding: 16px; margin-bottom: 12px; border-radius: var(--radius-md); }

  /* 6. Composer */
  .composer { padding: 16px 12px; }
  .composer-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }
  .composer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
  }
  .btn-primary, .btn-cancel {
    padding: 12px;
    font-size: 1rem;
  }

  /* 7. Toast — sits above bottom nav */
  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px));
    width: auto;
    text-align: center;
    justify-content: center;
  }

  /* 8. Sidebar sticky — on mobile just flow naturally */
  .app-sidebar {
    position: static;
    height: auto;
    overflow-y: visible;
  }
}