* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #1a1a1a;
  --bg-elevated: #222222;
  --text-primary: #f5f5f5;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --accent: #e84393;
  --accent-light: #fd79a8;
  --border: #2a2a2a;
  --nav-bg: rgba(10, 10, 10, 0.92);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tg-viewport-stable-height: 100vh;
  --tg-safe-top: env(safe-area-inset-top, 0px);
  --tg-content-safe-top: env(safe-area-inset-top, 0px);
  --tg-content-safe-bottom: env(safe-area-inset-bottom, 0px);
  --tg-content-safe-left: env(safe-area-inset-left, 0px);
  --tg-content-safe-right: env(safe-area-inset-right, 0px);
}

/* Telegram theme values are applied by app.js and retain these dark fallbacks
   in a normal browser. This also updates live when the device theme changes. */
body.tg-webapp {
  --bg-primary: var(--tg-theme-bg-color, #0a0a0a);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #141414);
  --bg-card: var(--tg-theme-section-bg-color, #1a1a1a);
  --text-primary: var(--tg-theme-text-color, #f5f5f5);
  --text-secondary: var(--tg-theme-hint-color, #a0a0a0);
  --accent: var(--tg-theme-button-color, #e84393);
  --accent-light: var(--tg-theme-link-color, #fd79a8);
}

html {
  overscroll-behavior: none;
  overflow-x: hidden;
  overflow-y: hidden;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  overflow-x: hidden;
  overflow-y: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 10px calc(var(--tg-content-safe-right) + 16px) 10px calc(var(--tg-content-safe-left) + 16px);
  padding-top: calc(var(--tg-content-safe-top) + 10px);
  background: rgba(10, 10, 10, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.header-logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-logo span {
  background: linear-gradient(135deg, var(--accent), #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Pages */
.page {
  display: none;
  padding-bottom: calc(80px + var(--tg-content-safe-bottom));
  min-height: calc(100vh - 60px);
}

.page.active {
  display: block;
}

#reelsPage {
  padding-bottom: 0;
  overflow: hidden;
  height: var(--tg-viewport-stable-height, 100vh);
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  padding: 16px calc(var(--tg-content-safe-right) + 16px) 12px calc(var(--tg-content-safe-left) + 16px);
}

/* Explore Grid */
.explore-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  padding: 0 calc(var(--tg-content-safe-right) + 8px) 0 calc(var(--tg-content-safe-left) + 8px);
}

.girl-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  aspect-ratio: 3/4;
  cursor: pointer;
  transition: transform 0.2s;
}

.girl-card:active {
  transform: scale(0.97);
}

.girl-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.girl-card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 40px 12px 12px;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
}

.girl-card-name {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.verified-badge {
  color: #3b82f6;
  font-size: 12px;
}

/* Profile Page */
.back-btn {
  position: absolute;
  top: calc(var(--tg-content-safe-top) + 12px);
  left: calc(var(--tg-content-safe-left) + 12px);
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(10px);
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-header {
  text-align: center;
  padding: 40px 20px 20px;
}

.profile-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  margin: 0 auto 16px;
  display: block;
}

.profile-name {
  font-size: 24px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.profile-username {
  color: var(--accent-light);
  font-size: 15px;
  margin-top: 4px;
}

.profile-bio {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 8px;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.profile-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.profile-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 30px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.profile-btn:active {
  transform: scale(0.95);
}

.btn-message {
  background: white;
  color: black;
}

.btn-share {
  background: var(--bg-elevated);
  color: white;
  border: 1px solid var(--border);
}

.profile-photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  margin-top: 24px;
}

.profile-photo {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
}

.profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.profile-photo:active img {
  transform: scale(1.05);
}

/* Reels */
.reels-header {
  position: fixed;
  top: calc(var(--tg-content-safe-top) + 8px);
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
  gap: 28px;
  padding: 8px 0;
  background: transparent;
  pointer-events: none;
}

.reels-tab {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 18px;
  border-radius: 20px;
  pointer-events: auto;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.reels-tab.active {
  color: white;
  background: rgba(255, 255, 255, 0.3);
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

.reels-container {
  height: var(--tg-viewport-stable-height, 100vh);
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: none;
  width: 100%;
}

.reel-item {
  height: var(--tg-viewport-stable-height, 100vh);
  scroll-snap-align: start;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
  width: 100%;
  overflow: hidden;
}

.reel-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.reel-loading-spinner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  z-index: 2;
}

/* Buffer progress bar */
.reel-buffer-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 15;
  background: rgba(255, 255, 255, 0.2);
}

.reel-buffer-fill {
  height: 100%;
  width: 0%;
  background: rgba(255, 255, 255, 0.7);
  transition: width 0.3s linear;
}

.reel-buffer-bar.loaded {
  opacity: 0;
  transition: opacity 0.5s ease;
}

.reel-overlay {
  position: absolute;
  bottom: calc(76px + var(--safe-bottom));
  left: 0;
  right: 60px;
  padding: 20px 16px 8px;
  background: none;
  pointer-events: none;
}

.reel-girl-info {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  pointer-events: auto;
}

.reel-girl-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid white;
}

.reel-girl-name {
  font-size: 15px;
  font-weight: 600;
}

.reel-caption {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.reel-actions {
  position: absolute;
  right: 12px;
  bottom: calc(140px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.reel-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
}

.reel-action-btn i {
  font-size: 24px;
  transition: transform 0.2s;
}

.reel-action-btn:active i {
  transform: scale(1.3);
}

.reel-action-btn.liked i {
  color: #ef4444;
}

.reel-action-btn span {
  font-size: 12px;
}

.reel-profile-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid var(--accent);
  cursor: pointer;
  position: relative;
}

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

.reel-profile-btn::after {
  content: '+';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* Bottom Sheet (Comments) */
.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
}

.bottom-sheet.hidden {
  display: none;
}

.sheet-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 70vh;
  background: var(--bg-secondary);
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.sheet-header button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
}

.comments-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.comment-item {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.comment-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.comment-body {
  flex: 1;
}

.comment-name {
  font-size: 13px;
  font-weight: 600;
}

.comment-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}

.comment-text {
  font-size: 14px;
  margin-top: 2px;
  line-height: 1.4;
}

.comment-actions {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.comment-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.comment-like-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 4px;
}

.comment-like-btn button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}

.comment-like-btn span {
  font-size: 11px;
  color: var(--text-muted);
}

.comment-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  padding-right: calc(16px + var(--tg-content-safe-right));
  padding-bottom: calc(12px + var(--tg-content-safe-bottom));
  padding-left: calc(16px + var(--tg-content-safe-left));
}

.comment-input input {
  flex: 1;
  background: var(--bg-elevated);
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  min-width: 0;
}

@supports (height: 100dvh) {
  :root { --tg-viewport-stable-height: 100dvh; }
}

@media (max-width: 360px) {
  .profile-header { padding-left: 12px; padding-right: 12px; }
  .profile-actions { flex-wrap: wrap; }
  .profile-btn { padding: 11px 18px; font-size: 14px; }
  .reel-actions { right: 8px; gap: 16px; }
  .reel-overlay { right: 54px; padding-left: 12px; }
  .comments-list { padding-left: 10px; padding-right: 10px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .app-header { padding-top: calc(var(--tg-content-safe-top) + 4px); padding-bottom: 4px; }
  .page-title { font-size: 22px; padding-top: 8px; }
  .profile-header { padding-top: calc(var(--tg-content-safe-top) + 16px); }
  .profile-avatar { width: 80px; height: 80px; margin-bottom: 8px; }
  .reels-header { top: calc(var(--tg-content-safe-top) + 2px); }
  .reel-actions { bottom: calc(80px + var(--safe-bottom)); gap: 12px; }
  .reel-overlay { bottom: calc(58px + var(--safe-bottom)); }
  .sheet-content { max-height: 90vh; }
}

.comment-send {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-right: var(--tg-content-safe-right);
  padding-bottom: calc(8px + var(--tg-content-safe-bottom));
  padding-left: var(--tg-content-safe-left);
}

/* Make nav transparent on reels page */
#reelsPage.active ~ .bottom-nav,
body.reels-active .bottom-nav {
  background: rgba(10, 10, 10, 0.6);
  border-top: none;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  padding: 6px;
  transition: color 0.2s;
}

.nav-btn i {
  font-size: 22px;
}

.nav-btn.active {
  color: var(--text-primary);
}

/* Loading */
.loading-state {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
}

/* Utilities */
.hidden { display: none !important; }

/* Scrollbar hide */
.reels-container::-webkit-scrollbar { display: none; }
.reels-container { -ms-overflow-style: none; scrollbar-width: none; }

/* TikTok-style video controls */
.reel-tap-area {
  position: absolute;
  top: 0;
  left: 0;
  right: 60px;
  bottom: 70px;
  z-index: 5;
  cursor: pointer;
}

.reel-pause-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 70px;
  height: 70px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.reel-pause-icon.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.reel-pause-icon i {
  font-size: 28px;
  color: white;
  margin-left: 4px;
}

/* Fixed global progress bar - sits exactly on top edge of nav */
.reels-fixed-progress {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: 20px;
  display: flex;
  align-items: flex-end;
  touch-action: none;
  pointer-events: auto;
}

.reels-fixed-progress.hidden {
  display: none;
}

.reels-fixed-progress-track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  position: relative;
  transition: height 0.15s;
}

.reels-fixed-progress.dragging .reels-fixed-progress-track {
  height: 6px;
}

.reels-fixed-progress-fill {
  height: 100%;
  background: white;
  width: 0%;
  position: relative;
}

.reels-fixed-progress-thumb {
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  opacity: 0;
  transition: opacity 0.15s;
}

.reels-fixed-progress.dragging .reels-fixed-progress-thumb {
  opacity: 1;
}
