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

:root {
  --bg: #fafafa;
  --card: #ffffff;
  --border: #dbdbdb;
  --text: #262626;
  --text-light: #8e8e8e;
  --primary: #0095f6;
  --primary-hover: #1877f2;
  --danger: #ed4956;
  --gradient: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  --nav-height: 54px;
  --bottom-height: 50px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Loading */
.loading-screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--card); z-index: 9999;
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loading-spinner.small { width: 24px; height: 24px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login-container {
  max-width: 380px; margin: 0 auto;
  padding: 40px 32px;
  min-height: 100vh;
  display: flex; flex-direction: column;
  justify-content: center;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 {
  font-size: 36px; font-weight: 700;
  background: var(--gradient); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-logo p { color: var(--text-light); margin-top: 8px; font-size: 14px; }

.auth-tabs {
  display: flex; border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1; padding: 12px; border: none; background: none;
  font-size: 14px; font-weight: 600; color: var(--text-light);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: .2s;
}
.auth-tab.active { color: var(--text); border-bottom-color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; background: #fafafa;
  outline: none; transition: border .2s;
}
.auth-form input:focus { border-color: var(--text-light); }

.btn-primary {
  padding: 12px; border: none; border-radius: 8px;
  background: var(--primary); color: white;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-outline {
  padding: 8px 20px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--card);
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: .2s;
}
.btn-outline:hover { background: #f0f0f0; }

.btn-google {
  width: 100%; padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; background: white;
  font-size: 14px; font-weight: 500;
  cursor: pointer; display: flex;
  align-items: center; justify-content: center; gap: 8px;
  transition: .2s;
}
.btn-google:hover { background: #f5f5f5; }

.divider {
  text-align: center; margin: 20px 0;
  position: relative;
}
.divider::before {
  content: ''; position: absolute; left: 0; top: 50%;
  width: 100%; height: 1px; background: var(--border);
}
.divider span {
  background: var(--card); padding: 0 16px;
  color: var(--text-light); font-size: 13px;
  position: relative;
}

.error-msg {
  color: var(--danger); font-size: 13px;
  text-align: center; margin-top: 12px;
}

/* Terms */
.terms-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
  cursor: pointer;
}
.terms-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.terms-check a, .terms-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}
.terms-check a:hover, .terms-footer a:hover {
  text-decoration: underline;
}
.terms-footer {
  text-align: center;
  font-size: 12px;
  color: var(--text-light);
  margin-top: 16px;
}
.terms-modal-content {
  max-height: 85vh;
  overflow-y: auto;
}
.terms-body {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}
.terms-body h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 18px 0 6px;
}
.terms-body p {
  margin-bottom: 10px;
}
.terms-body ul {
  margin: 0 0 12px 20px;
}
.terms-body li {
  margin-bottom: 4px;
}
.terms-updated {
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 14px;
}

/* Top Nav */
.top-nav {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--nav-height);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 16px; z-index: 100;
}
.nav-logo {
  font-size: 22px; font-weight: 700;
  background: var(--gradient); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.nav-actions { display: flex; gap: 8px; }
.nav-actions button, .btn-icon {
  background: none; border: none;
  font-size: 20px; color: var(--text);
  cursor: pointer; padding: 6px;
}

/* Search Panel */
.search-panel {
  position: fixed; top: var(--nav-height); left: 0; right: 0;
  background: var(--card); padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  z-index: 90;
}
.search-panel input {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #efefef; outline: none;
}
.search-results {
  max-height: 260px; overflow-y: auto; margin-top: 8px;
}
.search-result-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.search-result-item:hover { background: #fafafa; }

/* Bottom Nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-height);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex; z-index: 100;
}
.nav-tab {
  flex: 1; border: none; background: none;
  font-size: 22px; color: var(--text-light);
  cursor: pointer; transition: .2s;
}
.nav-tab.active { color: var(--text); }

/* Main Content */
.main-content {
  padding-top: calc(var(--nav-height) + 8px);
  padding-bottom: calc(var(--bottom-height) + 8px);
  max-width: 600px; margin: 0 auto;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Stories Bar */
.stories-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 8px 12px 12px;
  padding: 12px 8px;
  overflow: hidden;
}
.stories-list {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.stories-list::-webkit-scrollbar { display: none; }
.story-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  min-width: 66px;
}
.story-avatar-wrap {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  padding: 2px;
  background: var(--gradient);
  position: relative;
}
.story-avatar-wrap.add {
  background: var(--border);
}
.story-avatar-wrap.seen {
  background: var(--border);
}
.story-avatar-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--card);
}
.story-plus {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--card);
}
.story-username {
  font-size: 11px;
  color: var(--text);
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* Story Viewer */
.story-viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 500;
  display: flex;
  flex-direction: column;
}
.story-viewer-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 12px 10px;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(0,0,0,.6), transparent);
}
.story-progress-bar {
  display: flex;
  gap: 3px;
  margin-bottom: 10px;
}
.story-progress-segment {
  flex: 1;
  height: 2.5px;
  background: rgba(255,255,255,.35);
  border-radius: 2px;
  overflow: hidden;
}
.story-progress-segment .fill {
  height: 100%;
  background: #fff;
  width: 0;
  border-radius: 2px;
  transition: none;
}
.story-progress-segment .fill.active {
  animation: storyProgress 5s linear forwards;
}
.story-progress-segment .fill.done {
  width: 100%;
}
@keyframes storyProgress {
  from { width: 0; }
  to { width: 100%; }
}
.story-viewer-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}
.story-viewer-user strong { font-size: 14px; }
.story-viewer-time {
  font-size: 12px;
  color: rgba(255,255,255,.6);
}
.story-viewer-close {
  position: absolute;
  top: 36px;
  right: 12px;
  color: #fff !important;
  font-size: 22px;
}
.story-viewer-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.story-viewer-content img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.story-viewer-text {
  position: absolute;
  bottom: 60px;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-shadow: 0 1px 6px rgba(0,0,0,.7);
  padding: 0 20px;
}
.story-viewer-nav {
  position: absolute;
  inset: 0;
  display: flex;
  z-index: 5;
}
.story-nav-left, .story-nav-right {
  flex: 1;
  cursor: pointer;
}

/* Story Modal tweaks */
.story-preview img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 12px;
}

/* Suggested Users */
.suggested-section {
  padding: 16px; background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px; margin: 8px 12px 16px;
}
.suggested-section h3 {
  font-size: 14px; font-weight: 600;
  color: var(--text-light); margin-bottom: 12px;
}
.suggested-list { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 4px; }
.suggested-card {
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  min-width: 90px; cursor: pointer;
}
.suggested-card img {
  width: 56px; height: 56px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--border);
}
.suggested-card .name {
  font-size: 12px; font-weight: 600;
  text-align: center; max-width: 80px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.suggested-card .btn-follow-sm {
  font-size: 11px; padding: 4px 14px;
  border: none; border-radius: 6px;
  background: var(--primary); color: white;
  font-weight: 600; cursor: pointer;
}

/* Posts */
.post-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; margin: 0 12px 16px; overflow: hidden;
}
.post-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer;
}
.mini-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover;
}
.post-header strong { font-size: 14px; }
.post-image {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  cursor: pointer;
}
.post-actions {
  display: flex; gap: 12px; padding: 10px 14px;
}
.post-actions button {
  background: none; border: none;
  font-size: 22px; cursor: pointer; color: var(--text);
  display: flex; align-items: center; gap: 4px;
}
.post-actions button.liked { color: var(--danger); }
.post-actions button .count { font-size: 13px; font-weight: 600; }
.post-body { padding: 0 14px 12px; }
.post-body strong { font-size: 14px; margin-right: 6px; }
.post-body span { font-size: 14px; }
.post-date {
  display: block; font-size: 11px;
  color: var(--text-light); margin-top: 6px;
}

/* Explore Grid */
.explore-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 3px; padding: 0 12px;
}
.explore-grid .explore-item {
  aspect-ratio: 1; overflow: hidden;
  border-radius: 4px; cursor: pointer;
}
.explore-grid .explore-item img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .2s;
}
.explore-grid .explore-item:hover img { transform: scale(1.05); }

/* Profile */
.profile-header {
  display: flex; align-items: center; gap: 24px;
  padding: 20px 16px;
}
.profile-avatar { position: relative; }
.profile-avatar img {
  width: 80px; height: 80px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--border);
}
.avatar-edit {
  position: absolute; bottom: 0; right: 0;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer;
}
.profile-stats { display: flex; gap: 20px; }
.stat { text-align: center; }
.stat strong { display: block; font-size: 18px; }
.stat span { font-size: 12px; color: var(--text-light); }
.profile-info { padding: 0 16px 16px; }
.profile-info h2 { font-size: 16px; }
.profile-info p { font-size: 14px; color: var(--text-light); }
.profile-info .btn-outline, .profile-info .btn-primary {
  margin-top: 12px; width: 100%;
}
.profile-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 3px; padding: 0 12px;
}
.profile-grid .grid-item {
  aspect-ratio: 1; overflow: hidden; cursor: pointer;
}
.profile-grid .grid-item img {
  width: 100%; height: 100%; object-fit: cover;
}

.btn-back {
  background: none; border: none;
  font-size: 14px; font-weight: 600;
  color: var(--text); cursor: pointer;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 6px;
}

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal-content {
  background: var(--card); border-radius: 16px;
  width: 100%; max-width: 500px; padding: 20px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between;
  align-items: center; margin-bottom: 16px;
}
.modal-header h2 { font-size: 18px; }
.modal-content input, .modal-content textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit;
  outline: none; margin-bottom: 10px; resize: none;
}
.modal-content textarea { min-height: 80px; }

.upload-area {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px; padding: 40px;
  border: 2px dashed var(--border); border-radius: 12px;
  cursor: pointer; color: var(--text-light);
  margin-bottom: 12px; transition: .2s;
}
.upload-area:hover { border-color: var(--primary); color: var(--primary); }
.upload-area i { font-size: 32px; }

.post-preview img {
  width: 100%; max-height: 300px;
  object-fit: cover; border-radius: 8px;
  margin-bottom: 12px;
}

.char-count {
  text-align: right; font-size: 12px;
  color: var(--text-light); margin-bottom: 12px;
}

.progress-bar {
  height: 4px; background: #eee;
  border-radius: 2px; margin-top: 10px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary);
  width: 0; transition: width .3s;
}

/* Post Detail */
.post-detail {
  max-width: 560px; padding: 0; overflow: hidden;
}
.close-detail {
  position: absolute; top: 10px; right: 10px;
  color: white; font-size: 24px;
  z-index: 10; text-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.detail-image img {
  width: 100%; max-height: 420px; object-fit: cover;
}
.detail-body { padding: 14px; }
.detail-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.detail-text { font-size: 14px; margin-bottom: 12px; line-height: 1.5; }
.detail-actions {
  display: flex; gap: 16px;
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.detail-actions button {
  display: flex; align-items: center; gap: 4px;
  font-size: 14px;
}
.detail-actions button.liked i { color: var(--danger); font-weight: 900; }
.detail-comments { max-height: 200px; overflow-y: auto; margin-bottom: 10px; }
.comment-item {
  padding: 6px 0; font-size: 13px;
  border-bottom: 1px solid #f5f5f5;
}
.comment-item strong { margin-right: 6px; }
.comment-form {
  display: flex; gap: 8px; align-items: center;
}
.comment-form input {
  flex: 1; margin-bottom: 0;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 20px; font-size: 13px; outline: none;
}
.comment-form button {
  background: none; border: none;
  color: var(--primary); font-size: 18px; cursor: pointer;
}
.detail-date {
  display: block; font-size: 11px;
  color: var(--text-light); margin-top: 8px;
}
.delete-post { margin-left: auto; color: var(--danger) !important; }

/* Empty */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-light);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; }
.empty-state p { font-size: 14px; }
.feed-loading { text-align: center; padding: 20px; }

/* Default avatar */
img[src=""], img:not([src]) {
  background: linear-gradient(135deg, #667eea, #764ba2);
}

/* Responsive */
@media (min-width: 768px) {
  .login-container { padding-top: 80px; }
}
