/* ===== Instagram-style app shell ===== */

body.ig-app {
  padding-bottom: calc(56px + var(--safe-bottom));
}

body.ig-app .bg-pattern,
body.ig-app .grain {
  display: none;
}

body.ig-app .header {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: rgba(10, 10, 10, 0.98);
}

body.ig-app .menu-toggle,
body.ig-app .nav-drawer,
body.ig-app .nav-overlay {
  display: none !important;
}

body.ig-app .footer {
  display: none;
}

body.ig-app .fab {
  display: none;
}

body.ig-app.tab-feed .header {
  display: none;
}

body.ig-app:not(.tab-feed) .ig-header {
  display: none;
}

/* IG Header */
.ig-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--black);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ig-header-logo {
  font-family: var(--font-display);
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--white);
}

.ig-header-logo span {
  color: var(--yellow);
}

.ig-header-actions {
  display: flex;
  gap: 16px;
  align-items: center;
}

.ig-header-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
}

.ig-header-halal {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--yellow);
  border: 1px solid rgba(255, 204, 0, 0.35);
  border-radius: 100px;
}

/* Tab panels */
.tab-panel {
  display: none;
  position: relative;
  z-index: 1;
}

.tab-panel.active {
  display: block;
}

#tab-feed.active {
  padding-top: calc(52px + env(safe-area-inset-top, 0px));
  min-height: 60vh;
}

.feed-loading {
  padding: 48px 20px;
  text-align: center;
  color: var(--gray);
  font-size: 0.85rem;
}

.feed-retry-btn {
  display: block;
  margin: 0 auto 32px;
  padding: 10px 20px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  background: transparent;
  color: var(--gold);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

#tab-menu.active,
#tab-order.active,
#tab-profile.active {
  padding-top: 80px;
}

/* Bottom tab bar */
.ig-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: stretch;
  height: calc(56px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(10, 10, 10, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.ig-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--gray);
  font-size: 0.6rem;
  font-weight: 600;
  transition: color 0.2s;
}

.ig-tab svg {
  width: 26px;
  height: 26px;
}

.ig-tab.active {
  color: var(--yellow);
}

.ig-tab.active svg {
  filter: drop-shadow(0 0 6px rgba(255, 204, 0, 0.4));
}

/* Stories */
.stories-bar {
  display: flex;
  gap: 14px;
  padding: 14px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  -webkit-overflow-scrolling: touch;
}

.stories-bar::-webkit-scrollbar {
  display: none;
}

.story-item {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 72px;
}

.story-ring {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffcc00, #ff6600, #ffcc00);
  padding: 3px;
}

.story-thumb {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid var(--black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--yellow);
  background: var(--black-card);
}

.story-thumb--0 { background: linear-gradient(135deg, #1a1600, #0a0a0a); }
.story-thumb--1 { background: linear-gradient(135deg, #1a0800, #0a0a0a); }
.story-thumb--2 { background: linear-gradient(135deg, #141414, #0a0a0a); }
.story-thumb--3 { background: linear-gradient(135deg, #001a0a, #0a0a0a); }
.story-thumb--4 { background: linear-gradient(135deg, #1a001a, #0a0a0a); }

.story-label {
  font-size: 0.65rem;
  color: var(--white);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 72px;
}

/* Feed posts */
.feed {
  display: flex;
  flex-direction: column;
}

.ig-post {
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 8px;
  content-visibility: auto;
  contain-intrinsic-size: auto 520px;
}

.ig-post-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
}

.ig-post-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ig-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--yellow), var(--yellow-dark));
  color: var(--black);
  font-weight: 800;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ig-avatar--sm {
  width: 32px;
  height: 32px;
  font-size: 0.7rem;
}

.ig-post-user strong,
.ig-caption strong,
.ig-comment-preview strong,
.comment-item strong {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
}

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

.verified {
  flex-shrink: 0;
  vertical-align: middle;
}

.ig-location {
  display: block;
  font-size: 0.7rem;
  color: var(--gray);
}

.ig-more {
  font-size: 1rem;
  letter-spacing: 2px;
  color: var(--gray);
  padding: 8px;
}

.ig-post-title {
  padding: 0 14px 10px;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--white);
}

.ig-post-media {
  position: relative;
  aspect-ratio: 1;
  background: var(--black-soft);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

.post-art,
.post-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.post-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.ig-video-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}

.ig-video-sound {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.ig-video-sound:not(.is-muted) {
  opacity: 0;
}

.ig-stats {
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.ig-stats .ig-likes {
  display: inline;
}

.ig-stats-sep {
  margin: 0 6px;
  color: var(--gray);
}

.ig-views {
  font-size: inherit;
  color: var(--gray);
}

.story-media {
  width: 100%;
  max-height: 45vh;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 16px;
}

.ig-heart-burst {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transform: scale(0);
}

.ig-heart-burst.pop {
  animation: heartPop 0.8s ease forwards;
}

@keyframes heartPop {
  0% { opacity: 0; transform: scale(0); }
  15% { opacity: 1; transform: scale(1.2); }
  30% { transform: scale(0.95); }
  45% { transform: scale(1); opacity: 1; }
  100% { opacity: 0; transform: scale(1); }
}

.ig-post-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
}

.ig-actions-left {
  display: flex;
  gap: 14px;
}

.ig-action {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  transition: transform 0.15s;
}

.ig-action:active {
  transform: scale(0.85);
}

.like-btn.liked svg {
  animation: likeBounce 0.4s ease;
}

@keyframes likeBounce {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.ig-post-body {
  padding: 0 14px 16px;
}

.ig-likes {
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.ig-caption {
  font-size: 0.85rem;
  line-height: 1.45;
  margin-bottom: 6px;
}

.ig-comment-preview {
  font-size: 0.85rem;
  color: var(--white);
  margin-bottom: 4px;
}

.ig-view-comments {
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 6px;
  padding: 0;
}

.ig-inline-comment {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.ig-inline-comment-hint {
  margin: 0 0 6px;
  font-size: 0.75rem;
  color: var(--yellow);
  text-align: left;
}

.ig-inline-comment-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ig-inline-comment-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0;
  padding: 8px 0;
  color: var(--white);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.ig-inline-comment-input::placeholder {
  color: var(--gray);
}

.ig-inline-comment-input:focus {
  border-bottom-color: rgba(255, 204, 0, 0.35);
}

.ig-inline-comment-send {
  flex-shrink: 0;
  color: var(--yellow);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 0;
  opacity: 0.9;
}

.ig-inline-comment-send:active {
  opacity: 0.6;
}

.ig-time {
  display: block;
  font-size: 0.65rem;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 6px;
}

/* Comments sheet */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.comments-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  max-height: 75dvh;
  background: var(--black-soft);
  border-radius: 20px 20px 0 0;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.comments-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 10px auto 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sheet-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
}

.sheet-close {
  font-size: 1.5rem;
  color: var(--gray);
  padding: 4px 8px;
}

.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 120px;
  max-height: 40dvh;
}

.comment-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.comment-item p {
  font-size: 0.85rem;
  line-height: 1.4;
}

.comments-empty {
  text-align: center;
  color: var(--gray);
  font-size: 0.85rem;
  padding: 24px;
}

.comment-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: var(--black);
}

.comment-pending-hint {
  flex: 1 1 100%;
  margin: 0;
  font-size: 0.8rem;
  color: var(--yellow);
  text-align: center;
}

.comment-form input {
  flex: 1;
  background: var(--black-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 100px;
  padding: 12px 16px;
  color: var(--white);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.comment-form input:focus {
  border-color: rgba(255, 204, 0, 0.3);
}

.comment-form button {
  color: var(--yellow);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 8px 12px;
}

.comment-user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 0;
  font-size: 0.8rem;
  color: var(--gray);
}

.comment-logout {
  color: var(--yellow);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 4px 0;
}

.hidden {
  display: none !important;
}

.comment-auth,
.profile-auth {
  padding: 16px 20px 24px;
  text-align: center;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.telegram-login-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
  color: var(--black) !important;
  font-weight: 700;
  position: relative;
  z-index: 20;
  pointer-events: auto;
}

.telegram-login-btn svg {
  flex-shrink: 0;
}

.auth-hint {
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 12px;
}

.auth-hint a {
  color: var(--yellow);
}

.profile-user {
  margin-top: 16px;
  text-align: center;
}

.profile-user-name {
  color: var(--yellow);
  font-weight: 700;
  margin-bottom: 10px;
}

.profile-name-form {
  margin-bottom: 12px;
  text-align: left;
}

.profile-name-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.profile-name-form input {
  width: 100%;
  margin-bottom: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--black-soft);
  color: var(--white);
  font-family: inherit;
  font-size: 0.9rem;
}

.profile-name-hint {
  margin-top: 8px;
  margin-bottom: 0;
}

.profile-create textarea,
.profile-create input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--black-soft);
  color: var(--white);
  font-family: inherit;
  font-size: 0.9rem;
}

.profile-create textarea {
  resize: vertical;
  min-height: 100px;
}

/* Story viewer */
.story-viewer {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.story-viewer.open {
  opacity: 1;
  pointer-events: auto;
}

.story-progress {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 4px;
}

.story-bar {
  flex: 1;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.story-bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: #fff;
  border-radius: 2px;
}

.story-bar.active .story-bar-fill {
  animation: storyProgress 4.5s linear forwards;
}

.story-bar.done .story-bar-fill {
  width: 100%;
}

@keyframes storyProgress {
  from { width: 0; }
  to { width: 100%; }
}

.story-content {
  height: 100%;
}

.story-slide {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 48px 24px 24px;
}

.story-slide--yellow { background: linear-gradient(160deg, #1a1600, #0a0a0a); }
.story-slide--dark { background: linear-gradient(160deg, #141414, #0a0a0a); }
.story-slide--fire { background: linear-gradient(160deg, #1a0800, #0a0a0a); }

.story-slide-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: auto;
}

.story-slide-header strong {
  font-size: 0.85rem;
}

.story-slide-time {
  margin-left: auto;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.story-slide-body {
  text-align: center;
  padding-bottom: 20vh;
}

.story-slide-body h3 {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 12vw, 4rem);
  color: var(--yellow);
  letter-spacing: 0.05em;
  margin-bottom: 16px;
  line-height: 1;
}

.story-slide-body p {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.75);
  max-width: 280px;
  margin: 0 auto;
}

.story-tap-zones {
  position: absolute;
  inset: 0;
  display: flex;
  z-index: 1;
}

.story-tap-prev,
.story-tap-next {
  flex: 1;
  background: none;
  border: none;
}

.story-close {
  position: absolute;
  top: max(52px, calc(12px + env(safe-area-inset-top)));
  right: 16px;
  z-index: 3;
  color: #fff;
  font-size: 1.8rem;
  padding: 8px;
  line-height: 1;
}

/* Profile tab */
.profile-header {
  text-align: center;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--yellow), var(--yellow-dark));
  border: 3px solid rgba(255, 204, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--black);
  overflow: hidden;
  position: relative;
}

.profile-avatar--guest {
  background: var(--black-card);
  color: var(--gray);
  border-color: rgba(255, 255, 255, 0.08);
}

.profile-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-header--guest {
  padding-top: 48px;
}

.profile-actions--user {
  padding: 0 20px 16px;
  max-width: 360px;
  margin: 0 auto;
}

.profile-actions--user .btn {
  flex: 1;
  max-width: none;
}

.profile-name {
  font-family: var(--font-display);
  font-size: 1.8rem;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.profile-bio {
  font-size: 0.85rem;
  color: var(--gray);
  margin-bottom: 20px;
}

.profile-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
}

.profile-stat {
  text-align: center;
}

.profile-stat strong {
  display: block;
  font-size: 1.2rem;
  color: var(--yellow);
}

.profile-stat span {
  font-size: 0.7rem;
  color: var(--gray);
}

.profile-actions {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  justify-content: center;
}

.profile-actions .btn {
  flex: 1;
  max-width: 160px;
  padding: 10px;
  font-size: 0.85rem;
}

@media (min-width: 640px) {
  .feed,
  .stories-bar {
    max-width: 480px;
    margin: 0 auto;
  }

  .comments-sheet {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
  }

  .comments-sheet.open {
    transform: translateX(-50%) translateY(0);
  }
}

body.tg-login-open {
  overflow: hidden;
}

.tg-login-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tg-login-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.tg-login-modal__panel {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--card, #1a1a1a);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px 20px 20px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.tg-login-modal__close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: 0;
  background: transparent;
  color: var(--gray);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.tg-login-modal__title {
  margin: 0 0 8px;
  font-size: 1.15rem;
  text-align: center;
}

.tg-login-modal__hint {
  margin-top: 0;
}

.tg-login-steps {
  text-align: left;
  margin: 0 0 16px;
  padding-left: 20px;
  color: var(--gray);
  font-size: 0.9rem;
  line-height: 1.5;
}

.tg-login-steps a {
  color: var(--yellow);
  font-weight: 700;
}

.tg-login-code-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tg-login-code-input {
  width: 100%;
  text-align: center;
  letter-spacing: 0.35em;
  font-size: 1.4rem;
  font-weight: 700;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--white, #fff);
}

.tg-login-modal__error {
  color: #ff6b6b;
  margin-top: 8px;
}

.ig-caption-title {
  margin-bottom: 4px;
}

.menu-items-section {
  padding-bottom: 24px;
}

.menu-items-grid {
  display: grid;
  gap: 12px;
  padding: 0 20px 20px;
}

.menu-item-card {
  background: var(--black-card);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 16px;
}

.profile-avatar--upload {
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.profile-avatar-edit {
  position: absolute;
  inset: auto 0 0 0;
  background: rgba(0, 0, 0, 0.65);
  color: var(--yellow);
  font-size: 0.7rem;
  padding: 4px;
  text-align: center;
}
