/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg:          #ffffff;
  --bg-elevated: #fafafa;
  --bg-modal:    #ffffff;
  --border:      #dbdbdb;
  --text:        #262626;
  --text-secondary: #8e8e8e;
  --text-link:   #00376b;
  --accent:      #0095f6;
  --story-ring:  linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  --heart:       #ed4956;
  --separator:   #efefef;
  --nav-bg:      #ffffff;
  --nav-border:  #dbdbdb;
  --placeholder-bg: #efefef;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #000000;
    --bg-elevated: #121212;
    --bg-modal:    #1c1c1c;
    --border:      #262626;
    --text:        #f5f5f5;
    --text-secondary: #a8a8a8;
    --text-link:   #e0f1ff;
    --accent:      #0095f6;
    --separator:   #262626;
    --nav-bg:      #000000;
    --nav-border:  #262626;
    --placeholder-bg: #2a2a2a;
  }
}

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

.hidden { display: none !important; }

/* ─── Top Navigation Bar ────────────────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 44px;
}

.top-nav-back {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  padding: 8px 8px 8px 0;
  display: flex;
  align-items: center;
  font-size: 24px;
  line-height: 1;
}

.top-nav-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.top-nav-logo {
  flex: 1;
  font-size: 22px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.5px;
  color: var(--text);
}

.top-nav-icons {
  display: flex;
  gap: 16px;
  align-items: center;
}

.top-nav-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  font-size: 22px;
  padding: 4px;
}

/* ─── Profile Selector (Home Screen) ──────────────────────────────── */
.selector-page {
  padding: 24px 16px;
}

.selector-header {
  text-align: center;
  margin-bottom: 28px;
}

.selector-header h1 {
  font-size: 22px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  margin-bottom: 4px;
}

.selector-header p {
  font-size: 13px;
  color: var(--text-secondary);
}

.selector-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.selector-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
  color: inherit;
}

.selector-card:active { opacity: 0.7; }

.selector-card-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--placeholder-bg);
}

.selector-card-avatar.has-stories {
  padding: 3px;
  background: var(--story-ring);
}

.selector-card-avatar.has-stories img,
.selector-avatar-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg);
  background: var(--placeholder-bg);
  display: block;
}

.selector-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.selector-card-username {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: -6px;
}

/* ─── Profile Page ──────────────────────────────────────────────────── */
.profile-page {}

/* Avatar + Stats Row */
.profile-header {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.profile-avatar-wrap {
  flex-shrink: 0;
  width: 86px;
  height: 86px;
  border-radius: 50%;
  cursor: pointer;
}

.profile-avatar-wrap.has-stories {
  padding: 3px;
  background: var(--story-ring);
}

.profile-avatar-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--bg);
  background: var(--placeholder-bg);
  display: block;
}

.profile-stats {
  flex: 1;
  display: flex;
  justify-content: space-around;
}

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

.profile-stat-count {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.profile-stat-label {
  font-size: 12px;
  color: var(--text);
}

/* Bio */
.profile-bio {
  padding: 0 16px 12px;
}

.profile-display-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}

.verified-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
  flex-shrink: 0;
}

.profile-bio-text {
  font-size: 14px;
  color: var(--text);
  white-space: pre-line;
  line-height: 1.5;
}

/* Action Buttons */
.profile-actions {
  padding: 4px 16px 12px;
  display: flex;
  gap: 8px;
}

.btn-follow {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 0;
  cursor: pointer;
}

.btn-message {
  flex: 1;
  background: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 0;
  cursor: pointer;
}

/* Highlights */
.highlights-row {
  padding: 4px 0 12px;
  overflow-x: auto;
  display: flex;
  gap: 16px;
  padding-left: 16px;
  scrollbar-width: none;
}
.highlights-row::-webkit-scrollbar { display: none; }

.highlight-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.highlight-ring {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.highlight-cover {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--placeholder-bg);
  display: block;
}

.highlight-label {
  font-size: 11px;
  color: var(--text);
  text-align: center;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Tab Bar */
.profile-tabs {
  display: flex;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.profile-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
  border-bottom: 1px solid transparent;
  cursor: pointer;
  color: var(--text-secondary);
}

.profile-tab.active {
  border-bottom: 1px solid var(--text);
  color: var(--text);
}

.profile-tab svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* Post Grid */
.post-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}

.post-thumb {
  aspect-ratio: 1;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  background: var(--placeholder-bg);
}

.post-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s;
}

.post-thumb:active img { opacity: 0.85; }

/* ─── Story Overlay ─────────────────────────────────────────────────── */
.story-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 480px;
  margin: 0 auto;
}

.story-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.story-progress-bar {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  z-index: 10;
}

.story-progress-segment {
  flex: 1;
  height: 2px;
  background: rgba(255,255,255,0.4);
  border-radius: 2px;
  overflow: hidden;
}

.story-progress-fill {
  height: 100%;
  background: #fff;
  border-radius: 2px;
  width: 0%;
  transition: width linear;
}

.story-progress-fill.done { width: 100%; transition: none; }
.story-progress-fill.active { width: 0%; }

.story-close {
  position: absolute;
  top: 24px;
  right: 12px;
  z-index: 10;
  background: none;
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.story-user-info {
  position: absolute;
  top: 32px;
  left: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
}

.story-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid #fff;
  background: #333;
}

.story-username {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.story-timestamp {
  color: rgba(255,255,255,0.75);
  font-size: 12px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.story-tap-left,
.story-tap-right {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  z-index: 5;
  cursor: pointer;
}

.story-tap-left  { left: 0; }
.story-tap-right { right: 0; }

/* ─── Post Modal ────────────────────────────────────────────────────── */
.post-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  max-width: 480px;
  margin: 0 auto;
}

.post-modal {
  background: var(--bg-modal);
  width: 100%;
  max-height: 92vh;
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.post-modal::-webkit-scrollbar { display: none; }

.post-modal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.post-modal-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--placeholder-bg);
  cursor: pointer;
}

.post-modal-username {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.post-modal-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.post-modal-image-wrap {
  width: 100%;
  background: #000;
}

.post-modal-image {
  width: 100%;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.post-modal-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px 6px;
}

.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  padding: 2px;
}

.action-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action-btn.liked svg { fill: var(--heart); stroke: var(--heart); }

.action-btn-bookmark {
  margin-left: auto;
}

.post-modal-body {
  padding: 0 14px 24px;
}

.post-likes {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.post-caption {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.5;
}

.post-caption-username {
  font-weight: 700;
  margin-right: 4px;
}

.post-date {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}

.comments-section {
  border-top: 1px solid var(--separator);
  padding-top: 10px;
}

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

.comment-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--placeholder-bg);
  flex-shrink: 0;
  cursor: pointer;
}

.comment-body {
  flex: 1;
}

.comment-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

.comment-username {
  font-weight: 700;
  margin-right: 4px;
}

.comment-meta {
  display: flex;
  gap: 12px;
  margin-top: 3px;
  align-items: center;
}

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

.comment-like-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0;
}

/* ─── Mention Links ─────────────────────────────────────────────────── */
.mention-link {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}

/* ─── Error / Loading States ────────────────────────────────────────── */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  flex-direction: column;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.error-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 60vh;
  flex-direction: column;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

.error-screen h2 {
  font-size: 18px;
  color: var(--text);
}

/* ─── Bottom Nav Bar (decorative) ───────────────────────────────────── */
.bottom-nav {
  position: sticky;
  bottom: 0;
  background: var(--nav-bg);
  border-top: 1px solid var(--nav-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.bottom-nav-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
}

.bottom-nav-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bottom-nav-btn.active svg {
  fill: var(--text);
}

.bottom-nav-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--text);
  object-fit: cover;
  background: var(--placeholder-bg);
}
