@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #dbdbdb;
  --border-soft: #efefef;
  --text: #262626;
  --text-muted: #8e8e8e;
  --accent: #8b3dff;
  --accent-hover: #7526e6;
  --accent-soft: #f5eeff;
  --like: #ed4956;
  --radius: 12px;
  --sidebar-w: 245px;
  --nivo-gradient: linear-gradient(120deg, #ec4899 0%, #8b3dff 40%, #f97316 75%, #fbbf24 100%);
  --shadow-card: 0 1px 2px rgba(0,0,0,0.02);
  --shadow-card-hover: 0 10px 28px rgba(20,10,40,0.09);
}

[data-theme="dark"] {
  --bg: #0e0e12;
  --surface: #17171d;
  --border: #2b2b33;
  --border-soft: #24242b;
  --text: #f1f1f3;
  --text-muted: #93939c;
  --accent: #a463ff;
  --accent-hover: #b57aff;
  --accent-soft: #241a3a;
  --like: #f3576a;
  --shadow-card: 0 1px 2px rgba(0,0,0,0.25);
  --shadow-card-hover: 0 14px 34px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.25s ease, color 0.25s ease;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
img, video { max-width: 100%; display: block; }
::selection { background: var(--accent); color: white; }

body { animation: pageFadeIn 0.35s ease; }
@keyframes pageFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ===== Sidebar (desktop) ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  padding: 26px 16px;
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.brand {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800;
  font-size: 23px;
  letter-spacing: -0.02em;
  padding: 0 10px;
  margin-bottom: 34px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}
.brand img { width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0; }
.brand span {
  background: var(--nivo-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 15.5px;
  font-weight: 500;
  color: var(--text);
  transition: background 0.15s ease, transform 0.12s ease;
  width: 100%;
}
.sidebar-link:hover { background: var(--border-soft); transform: translateX(2px); }
.sidebar-link:active { transform: scale(0.97); }
.sidebar-link.active { font-weight: 700; }
.sidebar-link svg { flex-shrink: 0; }
.sidebar-link .nav-avatar-sm { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.sidebar-link.soon { cursor: pointer; user-select: none; }

.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }

.sidebar-cta {
  border: none; background: none; text-align: left;
}
.sidebar-cta .theme-icon { display: inline-flex; transition: transform 0.3s ease; }
.sidebar-cta:hover .theme-icon { transform: rotate(20deg); }

.more-wrap { position: relative; }
.more-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.16);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px) scale(0.98);
  transform-origin: bottom left;
  transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  z-index: 40;
}
.more-menu.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.more-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 12px; border-radius: 9px;
  background: none; border: none; color: var(--text);
  font-size: 14px; font-weight: 500; text-align: left;
  transition: background 0.15s ease;
}
.more-item:hover { background: var(--border-soft); }
.more-item svg { flex-shrink: 0; }
.more-divider { height: 1px; background: var(--border-soft); margin: 6px 4px; }

/* ===== Mobile top/bottom bars ===== */
.mobile-topbar, .mobile-bottombar { display: none; }

.mobile-topbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-soft);
  padding: 12px 18px;
  display: flex; align-items: center; justify-content: space-between;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.mobile-bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-soft);
  padding: 10px 24px calc(10px + env(safe-area-inset-bottom));
  align-items: center; justify-content: space-between;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}
.mobile-bottombar a, .mobile-bottombar button {
  background: none; border: none; color: var(--text); display: flex;
}
.mobile-bottombar img.nav-avatar-sm { width: 25px; height: 25px; border-radius: 50%; object-fit: cover; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .mobile-topbar, .mobile-bottombar { display: flex; }
  .app-main { padding-bottom: 70px; }
}
@media (min-width: 861px) {
  .app-main { margin-left: var(--sidebar-w); }
}

/* ===== Right panel (desktop, feed page) ===== */
.right-panel { display: none; }

@media (min-width: 1080px) {
  .app-main { display: flex; justify-content: center; gap: 44px; align-items: flex-start; padding: 0 24px; }
  .feed-wrap { margin: 0; }
  .right-panel {
    display: flex;
    flex-direction: column;
    width: 300px;
    flex-shrink: 0;
    padding: 30px 0 40px;
  }
}

.rp-me { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }
.rp-me img { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; transition: transform 0.2s ease; }
.rp-me a:hover img { transform: scale(1.05); }
.rp-me .rp-me-info { flex: 1; min-width: 0; }
.rp-me .rp-me-info .u { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-me .rp-me-info .n { font-size: 13.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-me .rp-switch { font-size: 12.5px; font-weight: 600; color: var(--accent); background: none; border: none; }

.rp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.rp-head span { font-size: 14px; font-weight: 600; color: var(--text-muted); }

.rp-suggestion {
  display: flex; align-items: center; gap: 12px;
  margin: 0 -8px 4px; padding: 6px 8px;
  border-radius: 10px;
  transition: background 0.15s ease, opacity 0.2s ease;
  animation: rpIn 0.35s ease backwards;
}
.rp-suggestion:hover { background: var(--border-soft); }
.rp-suggestion:nth-child(1) { animation-delay: 0.05s; }
.rp-suggestion:nth-child(2) { animation-delay: 0.1s; }
.rp-suggestion:nth-child(3) { animation-delay: 0.15s; }
.rp-suggestion:nth-child(4) { animation-delay: 0.2s; }
.rp-suggestion:nth-child(5) { animation-delay: 0.25s; }
@keyframes rpIn { from { opacity: 0; transform: translateX(6px); } to { opacity: 1; transform: translateX(0); } }
.rp-suggestion img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.rp-suggestion .rp-s-info { flex: 1; min-width: 0; }
.rp-suggestion .rp-s-info .u { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-suggestion .rp-s-info .sub { font-size: 12px; color: var(--text-muted); }
.rp-follow-btn { background: none; border: none; color: var(--accent); font-weight: 600; font-size: 12.5px; padding: 4px; border-radius: 6px; transition: color 0.15s ease, transform 0.1s ease; }
.rp-follow-btn:hover { color: var(--accent-hover); }
.rp-follow-btn:active { transform: scale(0.92); }
.rp-follow-btn.following { color: var(--text-muted); }

.rp-footer { margin-top: 28px; font-size: 11.5px; color: var(--text-muted); line-height: 1.8; }
.rp-footer .links span:not(:last-child)::after { content: " · "; }
.rp-footer .copyright { margin-top: 14px; text-transform: uppercase; letter-spacing: 0.02em; }

/* ===== Auth pages ===== */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 40px 32px 32px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.auth-card .brand { display: flex; justify-content: center; font-size: 28px; margin-bottom: 10px; }
.auth-card .brand img { width: 46px; height: 46px; border-radius: 12px; }
.auth-sub { text-align: center; color: var(--text-muted); font-size: 14.5px; margin-bottom: 28px; line-height: 1.4; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 14.5px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--nivo-gradient);
  color: white;
  border: none;
  border-radius: 9px;
  font-weight: 700;
  font-size: 14.5px;
  margin-top: 8px;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

.form-msg { font-size: 13px; margin-top: 10px; min-height: 18px; font-weight: 500; }
.form-msg.error { color: var(--like); }
.form-msg.ok { color: #2ba24c; }

.auth-switch { text-align: center; margin-top: 22px; font-size: 14px; color: var(--text-muted); }
.auth-switch a { color: var(--accent); font-weight: 700; }

/* ===== Feed ===== */
.feed-wrap { max-width: 470px; margin: 0 auto; padding: 24px 12px 60px; }

.stories-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding: 4px 4px 20px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
  scrollbar-width: none;
}
.stories-row::-webkit-scrollbar { display: none; }
.story-item { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; width: 66px; cursor: pointer; }
.story-ring {
  width: 60px; height: 60px; border-radius: 50%;
  padding: 2.5px;
  background: var(--nivo-gradient);
  transition: transform 0.2s ease;
}
.story-item:hover .story-ring { transform: scale(1.08); }
.story-ring img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 2.5px solid var(--surface); transition: border-color 0.25s ease; }
.story-item span { font-size: 11.5px; color: var(--text); max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.post-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform 0.2s ease;
  animation: cardIn 0.45s ease backwards;
}
.post-card:hover { box-shadow: var(--shadow-card-hover); transform: translateY(-2px); }
.post-card:nth-of-type(1) { animation-delay: 0.02s; }
.post-card:nth-of-type(2) { animation-delay: 0.08s; }
.post-card:nth-of-type(3) { animation-delay: 0.14s; }
.post-card:nth-of-type(4) { animation-delay: 0.2s; }
.post-card:nth-of-type(n+5) { animation-delay: 0.24s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }

.post-header { display: flex; align-items: center; gap: 11px; padding: 13px 15px; }
.post-header img.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-soft); }
.post-header .username { font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.post-header .time { font-size: 12.5px; color: var(--text-muted); margin-left: auto; }

.post-media { width: 100%; aspect-ratio: 1 / 1; background: var(--border-soft); display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.post-media img, .post-media video { width: 100%; height: 100%; object-fit: cover; }

.heart-pop {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  color: white;
  filter: drop-shadow(0 2px 10px rgba(0,0,0,0.35));
  pointer-events: none;
  opacity: 0;
}
.heart-pop.animate { animation: heartPop 0.75s ease; }
.heart-pop svg { width: 90px; height: 90px; }
@keyframes heartPop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  30% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  45% { transform: translate(-50%, -50%) scale(0.95); }
  80% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

.post-actions { display: flex; align-items: center; gap: 4px; padding: 11px 9px 2px; }
.icon-btn {
  background: none; border: none; color: var(--text);
  padding: 4px 6px; border-radius: 8px;
  display: inline-flex; align-items: center;
  transition: transform 0.12s ease, color 0.15s ease, background 0.15s ease;
}
.icon-btn:hover { background: var(--border-soft); }
.icon-btn:active { transform: scale(0.85); }
.icon-btn.liked { color: var(--like); }
.icon-btn.liked svg { animation: heartPop 0.4s ease; }

.post-likes { padding: 4px 15px 2px; font-size: 13.5px; font-weight: 600; }
.post-caption { padding: 5px 15px 4px; font-size: 14px; line-height: 1.45; }
.post-caption .username { font-weight: 600; margin-right: 6px; }
.post-comments-link { padding: 3px 15px 14px; font-size: 13.5px; color: var(--text-muted); display: block; font-weight: 500; }

.empty-state { text-align: center; color: var(--text-muted); padding: 70px 20px; font-size: 14.5px; }

.skeleton { background: linear-gradient(90deg, var(--border-soft) 25%, var(--surface) 37%, var(--border-soft) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-card { height: 460px; border-radius: var(--radius); margin-bottom: 20px; }

/* ===== Profile ===== */
.profile-wrap { max-width: 720px; margin: 0 auto; padding: 34px 16px 60px; }
.profile-head { display: flex; align-items: center; gap: 40px; margin-bottom: 30px; }
.profile-avatar { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-soft); flex-shrink: 0; }
.profile-info { flex: 1; }
.profile-top-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.profile-username { font-size: 19px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn-outline {
  padding: 8px 20px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 600;
  transition: background 0.15s ease, transform 0.1s ease;
}
.btn-outline:hover { background: var(--border-soft); }
.btn-outline:active { transform: scale(0.96); }
.btn-outline.follow { background: var(--nivo-gradient); border-color: transparent; color: white; }
.btn-outline.follow:hover { filter: brightness(1.06); }
.btn-outline.following { background: var(--surface); }

.profile-stats { display: flex; gap: 30px; margin-bottom: 14px; font-size: 14.5px; }
.profile-stats b { font-weight: 700; }
.profile-fullname { font-weight: 600; font-size: 14.5px; }
.profile-bio { font-size: 14px; color: var(--text); opacity: 0.85; white-space: pre-line; margin-top: 4px; line-height: 1.4; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; border-top: 1px solid var(--border-soft); padding-top: 24px; }
.grid-item { aspect-ratio: 1/1; background: var(--border-soft); overflow: hidden; border-radius: 4px; position: relative; transition: opacity 0.15s ease; }
.grid-item:hover { opacity: 0.9; }
.grid-item img, .grid-item video { width: 100%; height: 100%; object-fit: cover; }

/* ===== Post detail ===== */
.post-detail-wrap { max-width: 470px; margin: 0 auto; padding: 24px 12px 60px; }
.comments-list { padding: 8px 15px; display: flex; flex-direction: column; gap: 14px; max-height: 320px; overflow-y: auto; }
.comment-row { display: flex; gap: 10px; font-size: 14px; }
.comment-row img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.comment-row .cusername { font-weight: 600; margin-right: 6px; }
.comment-row .ctime { display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }

.comment-form { display: flex; gap: 8px; padding: 12px 15px 16px; border-top: 1px solid var(--border-soft); margin-top: 10px; }
.comment-form input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 20px;
  padding: 10px 15px; color: var(--text); font-size: 14px;
}
.comment-form input:focus { outline: none; border-color: var(--accent); }
.comment-form button { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 14px; padding: 0 6px; }
.comment-form button:disabled { color: var(--text-muted); }

.loading { text-align: center; color: var(--text-muted); padding: 40px; font-size: 14px; }

@media (max-width: 640px) {
  .profile-head { gap: 20px; }
  .profile-avatar { width: 78px; height: 78px; }
  .profile-stats { gap: 20px; font-size: 13.5px; }
}
