* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #000;
  --bg-secondary: #111;
  --bg-card: #1a1a1a;
  --text-primary: #fff;
  --text-secondary: #aaa;
  --accent: #fe2c55;
  --accent-hover: #ff4472;
  --border: #333;
  --nav-height: 50px;
  --header-height: 50px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.hidden { display: none !important; }

.screen {
  display: none;
  height: 100%;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
}

.screen.active { display: flex; }

/* ========== AUTH ========== */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 20px;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a0a1a 50%, #0a0a2a 100%);
}

.auth-logo {
  text-align: center;
  margin-bottom: 40px;
}

.logo-icon {
  font-size: 64px;
  margin-bottom: 10px;
}

.auth-logo h1 {
  font-size: 32px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #ff6f91, #845ec2);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-logo p {
  color: var(--text-secondary);
  margin-top: 5px;
}

#auth-form {
  width: 100%;
  max-width: 340px;
}

.auth-tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 10px;
  font-size: 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.auth-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.auth-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-fields input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-fields input:focus {
  border-color: var(--accent);
}

.auth-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-btn:hover { background: var(--accent-hover); }

.error-msg {
  color: var(--accent);
  text-align: center;
  font-size: 14px;
  margin-top: 10px;
}

/* ========== HEADER ========== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 0 16px;
  padding-top: var(--safe-top);
  background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
}

.header-title {
  display: none;
}

.header-tabs {
  display: flex;
  gap: 16px;
}

.header-tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 4px;
}

.header-tab.active {
  color: var(--text-primary);
}

.header-search {
  position: absolute;
  right: 16px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
}

/* ========== VIDEO FEED ========== */
.video-feed {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
}

.video-card {
  height: 100vh;
  width: 100%;
  position: relative;
  scroll-snap-align: start;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-player {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-tap-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  cursor: pointer;
}

.play-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 60px;
  opacity: 0;
  transition: all 0.2s;
  pointer-events: none;
}

.play-indicator.show {
  transform: translate(-50%, -50%) scale(1);
  opacity: 0.7;
}

/* ========== VIDEO ACTIONS (right side) ========== */
.video-actions {
  position: absolute;
  right: 10px;
  bottom: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  z-index: 10;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

.action-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid #fff;
  object-fit: cover;
  background: var(--bg-card);
}

.action-icon {
  font-size: 28px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
  transition: transform 0.15s;
}

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

.action-count {
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.like-action.liked .action-icon {
  color: var(--accent);
}

/* ========== VIDEO INFO (bottom) ========== */
.video-info {
  position: absolute;
  bottom: 70px;
  left: 12px;
  right: 80px;
  z-index: 10;
}

.video-username {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.video-caption {
  font-size: 14px;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ========== BOTTOM NAV ========== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 200;
}

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

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

.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; }

.upload-nav {
  position: relative;
  top: -5px;
}

.nav-icon-plus {
  width: 44px;
  height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 300;
  color: #fff;
}

/* ========== COMMENTS PANEL ========== */
.comments-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60vh;
  background: var(--bg-secondary);
  border-radius: 16px 16px 0 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

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

.comments-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.comments-header h3 { font-size: 15px; }

.close-comments {
  position: absolute;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  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-card);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.comment-body {
  flex: 1;
}

.comment-user {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.comment-text {
  font-size: 14px;
  color: var(--text-secondary);
}

.comment-time {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
}

.comments-input {
  display: flex;
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  gap: 8px;
}

.comments-input input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.comments-input button {
  background: var(--accent);
  border: none;
  border-radius: 20px;
  color: #fff;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}

/* ========== UPLOAD PANEL ========== */
.upload-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 300;
  display: flex;
  flex-direction: column;
}

.upload-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.close-upload {
  position: absolute;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
}

.upload-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 30px 20px;
  gap: 20px;
}

.upload-dropzone {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 9/16;
  max-height: 40vh;
  border: 2px dashed var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.upload-dropzone:hover, .upload-dropzone.has-file {
  border-color: var(--accent);
}

.upload-icon { font-size: 48px; }

.upload-dropzone p {
  color: var(--text-secondary);
  font-size: 14px;
}

.upload-caption {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
}

.upload-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 14px 40px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.upload-progress {
  width: 100%;
  max-width: 400px;
}

.progress-bar {
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s;
}

.progress-text {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* ========== DISCOVER PANEL ========== */
.discover-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 250;
  display: flex;
  flex-direction: column;
}

.discover-header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
}

.discover-header input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.search-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.search-user-info h4 { font-size: 15px; }
.search-user-info p { font-size: 13px; color: var(--text-secondary); }

/* ========== PROFILE PANEL ========== */
.profile-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  z-index: 250;
  display: flex;
  flex-direction: column;
}

.profile-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.profile-header h3 {
  flex: 1;
  text-align: center;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
}

.profile-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
}

.profile-avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: 12px;
}

#profile-displayname {
  font-size: 20px;
  font-weight: 700;
}

#profile-username {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 2px;
}

.profile-stats {
  display: flex;
  gap: 40px;
  margin: 20px 0;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat strong { font-size: 18px; }
.stat span { font-size: 12px; color: var(--text-secondary); }

.profile-videos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  width: 100%;
  max-width: 600px;
}

.profile-video-thumb {
  aspect-ratio: 9/16;
  background: var(--bg-card);
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

.profile-video-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-video-plays {
  position: absolute;
  bottom: 4px;
  left: 6px;
  font-size: 12px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* ========== SCROLLBAR ========== */
::-webkit-scrollbar { width: 0; }

/* ========== LOADING SPINNER ========== */
.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 20px auto;
}

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

/* ========== TOAST ========== */
.toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  z-index: 999;
  animation: fadeInOut 2.5s ease;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  85% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}
