:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-alt: #f5f5f5;
  --border: #e5e5e5;
  --text: #171717;
  --text-secondary: #737373;
  --primary: #171717;
  --primary-text: #ffffff;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

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

.screen { display: none; }
.screen.active { display: flex; }
.view { display: none; }
.view.active { display: block; }

/* Auth */
.auth-container {
  max-width: 400px;
  margin: 0 auto;
  padding: 60px 20px;
  width: 100%;
}

#auth-screen {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--surface);
}

.logo { text-align: center; margin-bottom: 40px; }
.logo h1 { font-size: 48px; font-weight: 700; letter-spacing: -2px; }
.tagline { color: var(--text-secondary); margin-top: 8px; }

.auth-form { display: none; }
.auth-form.active { display: block; }
.auth-form h2 { font-size: 24px; margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }
.form-group input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.2s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--text);
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: var(--primary-text);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s;
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-switch {
  text-align: center;
  margin-top: 20px;
  color: var(--text-secondary);
  font-size: 14px;
}
.auth-switch a { color: var(--text); font-weight: 600; text-decoration: none; }

.error-msg {
  color: var(--danger);
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
  min-height: 20px;
}

/* Top Nav */
.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
}

.nav-logo { font-size: 20px; font-weight: 700; letter-spacing: -1px; }
.nav-left, .nav-right { display: flex; align-items: center; gap: 8px; }
.nav-center { display: flex; gap: 4px; }

.nav-tab {
  padding: 8px 16px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.nav-tab.active { background: var(--surface-alt); color: var(--text); }

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text);
  transition: background 0.2s;
  font-size: 20px;
}
.btn-icon:hover { background: var(--surface-alt); }

.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  border: none;
  cursor: pointer;
  padding: 0;
  background: var(--surface-alt);
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* Main Content */
#main-screen { flex-direction: column; padding-top: 60px; min-height: 100vh; }

.feed-container { max-width: 600px; margin: 0 auto; padding: 20px; }

/* Composer */
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.composer.hidden { display: none; }
.composer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.composer-header h3 { font-size: 16px; }
.composer-body { padding: 16px 20px; }
.composer-body textarea {
  width: 100%;
  border: none;
  resize: none;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  background: transparent;
}
.composer-body textarea:focus { outline: none; }

.image-preview {
  position: relative;
  margin-top: 12px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.image-preview.hidden { display: none; }
.image-preview img { width: 100%; max-height: 400px; object-fit: cover; }
.image-preview .btn-icon {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: white;
  width: 32px;
  height: 32px;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.composer-actions .btn-primary { width: auto; padding: 8px 24px; }

/* Posts */
.posts-list { display: flex; flex-direction: column; gap: 16px; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.post-card:hover { box-shadow: var(--shadow); }

.post-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
}
.post-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-alt);
}
.post-avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 18px;
  flex-shrink: 0;
}
.comment-avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}
.post-user-info { flex: 1; }
.post-display-name { font-weight: 600; font-size: 15px; }
.post-username { color: var(--text-secondary); font-size: 13px; }
.post-time { color: var(--text-secondary); font-size: 12px; }

.post-content {
  padding: 0 20px 12px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.post-image {
  width: 100%;
  max-height: 500px;
  object-fit: cover;
}

.post-actions {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.post-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: none;
  background: none;
  font-size: 13px;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.post-action:hover { background: var(--surface-alt); }
.post-action.liked { color: var(--danger); }
.post-action.liked svg { fill: var(--danger); }

/* Profile */
.profile-container { max-width: 600px; margin: 0 auto; padding: 20px; }
.profile-header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.profile-pic {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-alt);
}
.profile-info { flex: 1; }
.profile-info h2 { font-size: 24px; }
.username { color: var(--text-secondary); font-size: 14px; margin-top: 2px; }
.bio { font-size: 15px; margin-top: 8px; line-height: 1.4; }
.profile-stats { margin-top: 12px; font-size: 14px; color: var(--text-secondary); }
.profile-stats strong { color: var(--text); }

/* Post Detail */
.back-btn {
  width: auto;
  height: auto;
  padding: 8px 16px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}
.detail-content { padding: 0; cursor: default; }
.detail-content .post-card { cursor: default; }

.comments-section { margin-top: 20px; }
.comments-section h3 { font-size: 16px; margin-bottom: 16px; }

.comment-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.comment-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-alt);
}
.comment-body { flex: 1; }
.comment-name { font-weight: 600; font-size: 14px; }
.comment-text { font-size: 14px; margin-top: 4px; line-height: 1.4; }
.comment-time { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.comment-input {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.comment-input input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}
.comment-input input:focus { outline: none; border-color: var(--text); }
.comment-input .btn-primary { width: auto; padding: 10px 20px; }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.search-bar input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
}
.search-bar input:focus { outline: none; border-color: var(--text); }

/* Loading */
.loading { text-align: center; padding: 40px; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); }

/* Mobile */
@media (max-width: 640px) {
  .feed-container { padding: 12px; }
  .profile-header { flex-direction: column; align-items: center; text-align: center; }
  .nav-center { display: none; }
}
